JS中与数组相关的函数

1. 添加数组元素

// 在数组元素的尾部追加元素
arrayObject.push(newelement1,newelement2,....,newelementX)

// 在数组元素的头部追加元素
arrayObject.unshift(newelement1,newelement2,....,newelementX)

// 在指定位置添加指定数量的元素
arrayObject.splice(index,howmany,element1,.....,elementX)

2. 删除数组元素

// 在数组元素的尾部删除元素
arrayObject.pop()

// 在数组元素的头部删除元素
arrayObject.shift()

// 在指定位置删除指定数量的元素
arrayObject.splice(index,howmany)

3. 数组合并与截取

// 截取从start开始到end结束的数组元素
arrayObject.slice(start[,end])

// 合并数组元素
arrayObject.concat(arrayX,arrayX,......,arrayX)

4. 连接数组元素

arrayObject.join(separator) // 相当于php中的implode

5. 切割字符串

stringObject.split(separator, howmany) // 相当于php中的explode
原文地址:https://www.cnblogs.com/chenjiacheng/p/6522556.html