移动端企业网站,python wordpress采集器,南京建设公司网站,wordpress创建页面打不开concat 的使用
concat() 方法用于合并两个或多个数组。此方法不会更改现有数组#xff0c;而是返回一个新数组。如果省略了所有参数#xff0c;则 concat 会返回调用此方法的现存数组的一个浅拷贝。
scriptvar arr1 [k, a, i…concat 的使用
concat() 方法用于合并两个或多个数组。此方法不会更改现有数组而是返回一个新数组。如果省略了所有参数则 concat 会返回调用此方法的现存数组的一个浅拷贝。
scriptvar arr1 [k, a, i];var arr2 [m, o];var arr3 [3, 1, 3];var result1 arr1.concat(arr2, arr3);console.log(result1-----, result1);var result2 arr1.concat(arr2, arr3, hello, 666);console.log(result2-----, result2);
/script手写 concat
scriptArray.prototype.kaimoConcat function (...args) {let newArr [...this];if (args.length 0) {return newArr;}args.forEach((el) {if (Array.isArray(el)) {newArr.push(...el);} else {newArr.push(el);}});return newArr;};var result3 arr1.kaimoConcat(arr2, arr3);console.log(result3---kaimoConcat--, result3);var result4 arr1.kaimoConcat(arr2, arr3, hello, 666);console.log(result4---kaimoConcat--, result4);
/script