1-1 增加

  1. push();
  2. unshift();
  3. concat();
  4. splice(index,0,...value) //从某个下标的前面增加

1-2 删除

  1. pop();
  2. shift();
  3. splice(index,howmany);

1-3 修改

  1. splice(index,howmany,...value)

1-4 查询

  1. indexOf();
  2. slice(startIndex,endIndex)
  3. includes() //判断数组是否包含某个值

1-5 其他

sort,reverse方法会改变数组的结构

  1. join(seprate)
  2. //升序,降序,求和
  3. arr.sort((a,b)=>a-b);
  4. arr.sort((a,b)=>b-a);
  5. arr.reduce((a,b)=>a+b);
  6. //取最大值
  7. Math.max(...arr);
  8. reverse() //对数组进行反转
  1. var arr = ["html","css","javascript"]
  2. console.log(arr.join()); // html,css,javascript
  3. console.log(arr.join("|")); // html|css|javascript
  4. console.log(arr.join("")); // htmlcssjavascript
  1. // 简单的算法实现
  2. var arr = [4,3,2,1]
  3. var minNum = arr[0]
  4. for(var i=1;i<arr.length;i++){
  5. if(minNum>arr[i]){
  6. minNum=arr[i]
  7. }
  8. }
  9. console.log(minNum);
  10. // Math.min(...arr) 取最小值
  11. var arr = [4,3,1]
  12. console.log(Math.min(...arr));
  1. <p id="p"></p>
  2. var p = document.getElementById("p")
  3. var arr = ["1994","犯罪","剧情"]
  4. var str = arr.join("/")
  5. p.innerHTML = str
  6. console.log(p);

1-6 遍历

  1. forEach();
  2. map();
  3. some();
  4. every();
  5. for-of;
  6. filter();
  7. findIndex();
  8. find();