首页 > 其他分享 >js常用数组的方法

js常用数组的方法

时间:2023-02-02 15:35:29浏览次数:50  
标签:function index 常用 arr js sort item 数组

  1. push() 从后面追加
  2. pop() 从后面删除
  3. unshift() 从前面添加
  4. shift() 从前面删除
  5. reverse() 反正数组
  6. splice() 截取并添加
  7. sort() 数组排序
    sort(function(a,b){return a-b})//升序
    sort(function(a,b){return b-a})//降序

以上是直接修改原始数组

  1. join() 连接字符
  2. concat() 拼接数组
  3. slice() 截取数组
  4. indexOf() 查找数组中对应内容的位置
  5. forEach(function(item,index,arr){}) 遍历数组 item数组的每一项 index是数组的索引 arr是原数组
  6. map(function(item,index,arr){}) 映射数组
  7. filter(function(item,index,arr){}) 过滤数组
  8. every(function(item,index,arr){}) 判断数组是否全部满足条件 返回布尔值
  9. some(function(item,index,arr){}) 判断数组里某项是否满足条件 返回布尔值

标签:function,index,常用,arr,js,sort,item,数组
From: https://www.cnblogs.com/czjjy/p/17086018.html

相关文章