JavaScript-Array的知识总结

发布于:2023-01-06 ⋅ 阅读:(353) ⋅ 点赞:(0)
试读部分
数组方法中那些会改变原数组? 那些不会? 会改变原数组 push unshift pop shift sort reverse 不会改变原数组 concat join split forEach map reduce slice findIndex find 实践 会改变原数组的属性 1. push:在数组尾部添加,返回的是新数组的长度 // 1. push:在数组尾部添加,返回的是新数组的长度 // (method) Array<string>.push(...items: string[]): number const arr = ['nice','a','day','1','2','3']; let arrPush = arr.push('push') console.log('arrpush','返回值:', arrPush, arr); // arrpush 返回值: 7 ['nice', 'a', 'day', '1', '2', '3', 'push'] 2. unshift:在数组尾部添加,返回的是新数组的长度 // 2. unshift: 在数组的头部添加一个新元素,返回的是新数组的长度 // (method) Array<string>.unshift(...items: string[]): number const arr = ['nice','a','day','1','2','3']; let arrUnshift = arr.unshift('unshift') console.log('unshift', '返回值:',arrUnshift,'原数组:', arr); // unshift 返回值: 8 原数组:[ 'unshift', 'nice', 'a', 'day', '1', '2', '3', 'push' ] 3. po……
本文为 VIP 文章,已展示部分内容,开通 VIP 后查看全文

觉得这篇文章有帮助?

点个赞,或赞赏支持作者持续创作

微信公众号

今日签到

点亮在社区的每一天
去签到