Array.prototype.slice()
会改变原本的阵列,回传值是一个包含被删除的元素阵列
array.splice(start[, deleteCount[, item1[, item2[, ...]]]])
onst months = ['Jan', 'March', 'April', 'June'];months .slice(1, 2); // 回传值 ['March']console.log(months) // ['Jan', 'March', 'April', 'June']
Array.prototype.splice()
不会改变原本的阵列,回传值是一个新的阵列
arr.slice([begin[, end]])
const months = ['Jan', 'March', 'April', 'June'];months.splice(1, 2); // 回传值 ['March', 'April']console.log(months) // ['Jan', 'June']
Array.prototype.find()
不会改变原本的阵列,回传 "第一个" 满足所提供之测试函式的元素值。
arr.find(callback[, thisArg])
const array1 = [5, 12, 8, 130, 44];array1.find(element => element > 10); // 回传值 12console.log(array1) // [5, 12, 8, 130, 44]
Array.prototype.filter()
不会改变原本的阵列,回传 "所有" 满足所提供之测试函式的元素值。
arr.filter(callback(element[, index[, array]])[, thisArg])
const array1 = [5, 12, 8, 130, 44]array1.filter(element => element > 10); // 回传值 [12, 130, 44]console.log(array1) // [5, 12, 8, 130, 44]