const array1 =[1,2,3,4];// fill with 0 from position 2 until position 4
console.log(array1.fill(0,2,4));// expected output: [1, 2, 0, 0]// fill with 5 from position 1
console.log(array1.fill(5,1));// expected output: [1, 5, 5, 5]
console.log(array1.fill(6));// expected output: [6, 6, 6, 6]
findIndex
const array1 =[5,12,8,130,44];constisLargeNumber=(element)=> element >10;// 返回第一个满足条件的数const found = array1.find(isLargeNumber);
console.log(found);// 返回第一个满足条件的数的索引
console.log(array1.findIndex(isLargeNumber));
复制数组
// slice() 抽取当前数组中的一段元素组合成一个新数组。let arr =['kobe','bryant'];
console.log(arr.slice());// copyWithin 浅复制数组的一部分到同一数组中的另一个位置,并返回它,不会改变原数组的长度。const array1 =['a','b','c','d','e'];// copy to index 0 the element at index 3
console.log(array1.copyWithin(0,3,4));// expected output: Array ["d", "b", "c", "d", "e"]// copy to index 1 all elements from index 3 to the end
console.log(array1.copyWithin(1,3));// expected output: Array ["d", "d", "e", "d", "e"]
some() 方法测试数组中是不是至少有1个元素通过了被提供的函数测试。它返回的是一个Boolean类型的值。
// 如果用一个空数组进行测试,在任何情况下它返回的都是false。const array =[1,2,3,4,5];// checks whether an element is evenconsteven=(element)=> element %2===0;
console.log(array.some(even));// expected output: true// 具体使用场景?????????