js数组方法全解

  • 时间:2022-03-15 15:12 作者:醉青风 来源: 阅读:4937
  • 扫一扫,手机访问
摘要:let list = [1,2,3,4,5,6,3]let list2 =    list.map((el)= {return el=el+1})  //map 解决每个元素,并把返回的值组成新数组 console.log(” list2 ”, list2 ) //list2  (6) [2, 3,

let list = [1,2,3,4,5,6,3]

let list2 =    list.map((el)=>{return el=el+1})  //map 解决每个元素,并把返回的值组成新数组

console.log(" list2 ", list2 ) //list2  (6) [2, 3, 4, 5, 6, 7]

let list3 =    list.filter((el)=>{return el>3}) //filter 返回符合判断的元素组成数组

console.log(" list3 ", list3 )//list3  (3) [4, 5, 6]

let list4 =    list.some((el)=>{return el>3}) // some  判断元素能否符合判断,只有有一个符合就返回 true

console.log(" list4 ", list4 )//list4  true

let list5 =    list.every((el)=>{return el>3}) // every  判断元素能否一律符合判断

console.log(" list5 ", list5 )//list5  false

let list6 =    Array.isArray(list ) // every  判断元素能否是数组

console.log(" list6 ", list6 )// list6 true

let list7 =    list.indexOf(13) // 找数组中能否存在该元素,有则返回该元素的下角标,否则返回-1

console.log(" list7 ", list7 )// list7  2

let list8 =    list.lastIndexOf( 2,13) // 找数组中能否存在(符合条件的元素),只有有一个符合则返回该元素的下角标,否则返回-1

console.log(" list8 ", list8 )// list8 1

list.splice( 2,0,9) // splice():删除、插入和替换。使用  splice(起始位置、 0(要删除的项数)和要插入的项)。会改变原数据

console.log(" list  ",  list)// list  [1, 2, 9, 3, 4, 5, 6, 3]

let list9 =  list.slice( 2,8) // slice(): 根据下角标截取数据,不会改变原数据

console.log(" list9 ", list9 , list)// list  [1, 2, 9, 3, 4, 5, 6, 3]

// sort() 排序

// reverse():反转数组项的顺序

// concat() :合并数组

// shift():删除原数组第一项,并返回删除元素的值;假如数组为空则返回undefined 。

// unshift:将参数增加到原数组开头,并返回数组的长度 。

//push():  把里面的内容增加到数组末尾,并返回修改后的长度。

//pop():移除数组最后一项,返回移除的那个值,减少数组的length。

//join,就是把数组转换成字符串,而后给他规定个连接字符,默认的是逗号(  ,)

  • 全部评论(0)
最新发布的资讯信息
【系统环境|】2FA验证器 验证码如何登录(2024-04-01 20:18)
【系统环境|】怎么做才能建设好外贸网站?(2023-12-20 10:05)
【系统环境|数据库】 潮玩宇宙游戏道具收集方法(2023-12-12 16:13)
【系统环境|】遥遥领先!青否数字人直播系统5.0发布,支持真人接管实时驱动!(2023-10-12 17:31)
【系统环境|服务器应用】克隆自己的数字人形象需要几步?(2023-09-20 17:13)
【系统环境|】Tiktok登录教程(2023-02-13 14:17)
【系统环境|】ZORRO佐罗软件安装教程及一键新机使用方法详细简介(2023-02-10 21:56)
【系统环境|】阿里云 centos 云盘扩容命令(2023-01-10 16:35)
【系统环境|】补单系统搭建补单源码搭建(2022-05-18 11:35)
【系统环境|服务器应用】高端显卡再度登上热搜,竟然是因为“断崖式”的降价(2022-04-12 19:47)
手机二维码手机访问领取大礼包
返回顶部