js数组操作
1. splice
删除
- 特点:数组中元素删除后数组会自动更新,后面下标会补位
list(index, count)
// index即为要删除的集合下标
// count 为数量
2. delete
删除
- 特点:数组中元素删除后变为undifine,数组长度不发生变化
delete list[1]
3. sort
排序
var arr = [10,20,5,1]
arr.sort(function(x,y){
if(x < y) {
return -1
} else if (x > y) {
return 1
} else {
return 0
}
})
console.log('从小到大',arr)