<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Javascript 字符串、數(shù)字、數(shù)組

          共 2272字,需瀏覽 5分鐘

           ·

          2021-10-02 17:09

          英文 | https://programmer-anamul.medium.com/javascript-string-number-array-18378f26c692
          翻譯 | 楊小二

          Javascript 是最流行的編程語言。目前,F(xiàn)acebook、YouTube 等大多數(shù)大型網(wǎng)站都在使用 JavaScript。所以,讓我們學(xué)習(xí)一些關(guān)于 JavaScript 字符串、數(shù)字和數(shù)組的基本知識(shí)。
          String
          JavaScript 字符串用于存儲(chǔ)和操作文本。JavaScript 字符串存儲(chǔ)了一系列字符,如“Anamul Hoque”。
          Javascript 提供了一些方法來處理 Javascript 字符串,如下所示:
          01、String.length()
          String.length() 方法用于查找字符串的長度,使用內(nèi)置的 length 屬性。
          const name = "Hey I am Anamul Hoque";console.log(name.length)

          02、string.charAt():

          string.charAt() 方法返回字符串中指定索引處的字符。第一個(gè)字符的索引為 0,第二個(gè)字符的索引為 1,以此類推。字符串中最后一個(gè)字符的索引是 string.length-1。

          const name = "Hey I am Anamul Hoque";const result = name.charAt(str.length-1);console.log(result)

          03、string.concat():

          string.contact() 方法用于連接兩個(gè)或多個(gè)字符串。

          const fristName = "Md Anamul "const lastName = "Hoque"const fullName = fristName.conact(lastName)console.log(fullName)

          04、string.includes():

          string.includes() 方法確定字符串是否包含指定字符串的字符。結(jié)果總是返回 true 或 false 值。

          const name = "Hi, I am Anamul Hoque"const result = name.includes("Anamul") //trueconst result2 = name.includes("Bangladesh") // false

          Number

          Number 是 javascript 的一種數(shù)據(jù)類型,它用于表示和操作數(shù)字,如 67 或 -9, 0.4 。

          Javascript 提供了一些使用 Javascript Number 的方法。如下所示:

          01、Math.abs():

          abs() 方法返回?cái)?shù)字的絕對(duì)值。

          const number = -4.76const result = Math.abs(number);console.log(result)

          02、Math.random():

          Math.random() 方法返回一個(gè)從 0 到1,但不包括 1 的隨機(jī)數(shù)。

          const number = Math.random();console.log(number)

          03、Math.round():

          Math.round() 方法將數(shù)字四舍五入到最接近的整數(shù)。

          const number = Math.round(8.97876);console.log(number)

          04、Math.sqrt():

          Math.sqrt() 方法用于求一個(gè)數(shù)的平方根。

          const number = Math.sqrt(99);console.log(number)

          Array:

          數(shù)組是一種特殊類型的對(duì)象,用于在單個(gè)變量中存儲(chǔ)多個(gè)值。

          Javascript 提供了一些方法來處理 Javascript 數(shù)組,如下所示:

          01、array.concact():

          array.contact() 方法用于合并兩個(gè)或多個(gè)數(shù)組。

          const array1 = ['a', 'b', 'c'];const array2 = ['d', 'e', 'f'];const result = array1.concat(array2);console.log(result)

          02、array.filter():

          array.filter() 方法創(chuàng)建一個(gè)數(shù)組,其中填充了作為函數(shù)通過測試的所有數(shù)組元素。

          const ages = [12,13,24,12,56,32]const result = age.filter(age => age > 20)console.log(result)

          03、array.map():

          array.map() 方法使用為每個(gè)數(shù)組元素調(diào)用函數(shù)的結(jié)果創(chuàng)建一個(gè)新數(shù)組。

          const ages = [12,13,24,12,56,32]const restlt = ages.map(age => age.age)console.log(result)

          除了這些,還有一些其他的方法。 

          今天內(nèi)容就分享到這里,感謝你的時(shí)間,謝謝閱讀!


          學(xué)習(xí)更多技能

          請(qǐng)點(diǎn)擊下方公眾號(hào)

          瀏覽 57
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  亚洲男人电影天堂 | 内射免费视频 | 91麻豆天美成人电影 | 成人免费毛片 嘿嘿连载视频 | 影音先锋成人资源在线 |