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

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)
![]()

