当前位置:网站首页>数组自带的方法

数组自带的方法

2022-06-23 15:25:00 暴躁李子 在线摆烂

Array.prototype.at()

at() 方法接收一个整数值并返回该索引的项目,允许正数和负数。
负整数从数组中的最后一个项目开始倒数

// 一个函数,用于返回给定数组的最后一个项目
function returnLast(arr) {
    
  return arr.at(-1);
}
const a=[{
    name:'1'},{
    name:'2'},{
    name:'3'}]

a.at(0) // {name: '1'}

a.at(-1) // {name: '3'}

this.returnLast(a) // {name: '3'}

Array.prototype.concat()

concat() 方法用于合并两个或多个数组。此方法不会更改现有数组,而是返回一个新数组


const array1 = ['a', 'b', 'c'];
const array2 = ['a', 'e', 'f'];
const array3 = [1,2,3];

//array1.concat(array2); Array ["a", "b", "c", "a", "e", "f"]

//array1.concat(array2,array3); Array ["a", "b", "c", "a", "e", "f", 1, 2, 3]

at: ƒ at()
concat: ƒ concat()
constructor: ƒ Array()
copyWithin: ƒ copyWithin()
entries: ƒ entries()
every: ƒ every()
fill: ƒ fill()
filter: ƒ filter()
find: ƒ find()
findIndex: ƒ findIndex()
findLast: ƒ findLast()
findLastIndex: ƒ findLastIndex()
flat: ƒ flat()
flatMap: ƒ flatMap()
forEach: ƒ forEach()
includes: ƒ includes()
indexOf: ƒ indexOf()
join: ƒ join()
keys: ƒ keys()
lastIndexOf: ƒ lastIndexOf()
length: 0
map: ƒ map()
pop: ƒ pop()
push: ƒ push()
reduce: ƒ reduce()
reduceRight: ƒ reduceRight()
reverse: ƒ reverse()
shift: ƒ shift()
slice: ƒ slice()
some: ƒ some()
sort: ƒ sort()
splice: ƒ splice()
toLocaleString: ƒ toLocaleString()
toString: ƒ toString()
unshift: ƒ unshift()
values: ƒ values()
Symbol(Symbol.iterator): ƒ values()

原网站

版权声明
本文为[暴躁李子 在线摆烂]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_47353884/article/details/125317389