标签:length 第一个 ber reduce 截取 star for 循环 正序
let arr1 = [1,2,3]; let arr2 = [4,5,6]; console.log(arr1.concat(arr2)); // [1,2,3,4,5,6] console.log(arr1.concat(4,5)) // [1,2,3,4,5] console.log(arr1); // [1,2,3]
let arr = [1,2,3]; console.log(arr.join(‘|‘)); // 1|2|3 console.log(typeof arr.join(‘|‘)); // string console.log(arr); // [1,2,3]
let arr = [1,2,3]; console.log(arr.pop()); // 3 console.log(typeof arr.pop()) // number console.log(arr); // [1,2]
let arr = [1,2,3]; let arr1 = [4,5]; // console.log(arr.push(arr1)); // 4 [1,2,3,[4,5]] console.log(arr.push(4,5)); // 5 console.log(arr); // [1,2,3,4,5]
let arr = [1,2,3]; console.log(arr.shift()); // 1 console.log(arr); // [2,3]
let arr = [1,2,3,4]; console.log(arr.unshift(5,6)); // 6 console.log(arr); // [5,6,1,2,3,4]
let arr = [1,4,3,2]; console.log(arr.sort()); // [1,2,3,4] console.log(arr) // [1,2,3,4]
let arr = [1,4,3,2]; console.log(arr.reverse()); // [2,3,4,1] console.log(arr); // [2,3,4,1] console.log(arr.sort().reverse() ) // [4,3,2,1]
let arr = [1,2,3,4]; console.log(arr.slice(0,1)); // [1] console.log(arr.slice(0,2)); // [1,2] console.log(arr.slice(1,2)); // [2] console.log(arr.slice(2,2)); // [] console.log(arr.slice(0,3)); // [1,2,3] console.log(arr); // [1,2,3,4]
let arr = [1,2,3,4,5]; // console.log(arr.splice(1,1)); // [2] // console.log(arr); // [1,3,4,5] // console.log(arr.splice(1,2)); // [2,3] // console.log(arr.splice(1,2,6)); // [1,6,4,5] console.log(arr.splice(1,2,...[6,7,8,9])); // [1,6,8,9,4,5] console.log(arr); // [1,6,8,9,4,5]
let arr = [‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘] arr.map( (c, i) => { console.log(i+‘.‘+" "+c)
// 可以return })
let arr = [12, 5, 865, 3570]; let result = arr.reduce((temp, item, index) => { return temp + item; // temp是每次两个数相加的临时和,第一次是12+5,第二次是17+865,第三次是882+3570 }) console.log(result); // 12+5 +865+3570
let arr = [50, 150, 1800, 2500]; let result = arr.filter( c => c>=1800) console.log(result);
let arr = [50, 150, 1800, 2500]; arr.forEach( item => { console.log(item); })
标签:length 第一个 ber reduce 截取 star for 循环 正序
原文地址:https://www.cnblogs.com/Xmforever/p/10318006.html