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
posted @ 2016-11-16 14:57  chenjiacheng  阅读(228)  评论(0编辑  收藏  举报