1-1 增加
push();
unshift();
concat();
splice(index,0,...value) //从某个下标的前面增加
1-2 删除
pop();
shift();
splice(index,howmany);
1-3 修改
splice(index,howmany,...value)
1-4 查询
indexOf();
slice(startIndex,endIndex)
includes() //判断数组是否包含某个值
1-5 其他
sort,reverse方法会改变数组的结构
join(seprate)
//升序,降序,求和
arr.sort((a,b)=>a-b);
arr.sort((a,b)=>b-a);
//只能对简单值求和[1,2,3]
arr.reduce((a,b)=>a+b);
//取最大值
Math.max(...arr);
reverse() //对数组进行反转
var arr = ["html","css","javascript"]
console.log(arr.join()); // html,css,javascript
console.log(arr.join("|")); // html|css|javascript
console.log(arr.join("")); // htmlcssjavascript
// 简单的算法实现
var arr = [4,3,2,1]
var minNum = arr[0]
for(var i=1;i<arr.length;i++){
if(minNum>arr[i]){
minNum=arr[i]
}
}
console.log(minNum);
// Math.min(...arr) 取最小值
var arr = [4,3,1]
console.log(Math.min(...arr));
<p id="p"></p>
var p = document.getElementById("p")
var arr = ["1994","犯罪","剧情"]
var str = arr.join("/")
p.innerHTML = str
console.log(p);
1-6 遍历
forEach();
map();
some();
every();
for-of;
for-in; 也能对对象执行遍历
filter();
findIndex();
find();