let arr0 = [1, 2, 3]; let arr1 = new Array(1, 2, 3); console.log(arr0, arr1);
let arr0 = [1, 2]; let arr1 = arr0; arr1.push(3) arr0 = [1, 3];//指向别的内存
let [a, b] = [1, 3];
let [, , , , a] = [1, 2, 3, 4, 5]; //a=5
[a, b] = [b, a];
let [a, ...rest] = [1, 2, 3, 4, 5] //a=1 //rest=[2,3,4,5]
let [name, age = 18, gender] = ['gl', , 'male'] let [name, age = 18] = ['gl']
let a = [1, 2, 3]; let b = [...a];
console.log(typeof [1, 2]);//object console.log(Array.isArray([1, 2]));//true
let arr0 = [1, 2, 3]; let arr1 = [3, 4, 5]; console.log(arr0.concat(arr1));//1, 2, 3, 3, 4, 5 console.log(arr0);//1, 2, 3 console.log(arr0.join('-'));//1-2-3
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; let res = arr.slice(2, 4); console.log(res);//3,4 console.log(arr);//不变
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; let res = arr.splice(2, 2); console.log(res);//[3,4] console.log(arr);//[1,2,5,6,7,8,9] arr.splice(2, 1, 8, 8); console.log(arr);//[1,2,8,8,6,7,8,9];5被删除,插入|增加了2个8
function shuffle(arr) { let tmp = []; while (arr.length > 0) { let rad = Math.floor(Math.random() * arr.length) tmp.push(arr[rad]) arr.splice(rad, 1) } return tmp; }