let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
console.log(arr.push(10, 11));
console.log('push', arr);
console.log('pop', arr.pop())
console.log('shift', arr.shift())
console.log('unsift', arr.unshift(1, 11));
const concat = arr.concat(['a', 'aaa'], ['b'], 'c', 'd')
console.log('concat', concat);
const str = arr.join('-')
console.log('str', str);
console.log('reverse', arr.reverse());
console.log('arr', arr);
let sortArr = [7, 3, 2, 6, 4, 3, 9, 56]
console.log('sort', sortArr.sort((a, b) => { return a - b }));
console.log('sortArr', sortArr);
let mySortArr = [7, 3, 2, 6, 4, 3, 9, 56]
function sort(arr, fn) {
for (var i = 0; i <= arr.length - 1; i++) {
for (var j = 0; j < arr.length - i; j++) {
if (fn(arr[j], arr[j + 1]) > 0) {
var temp;
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp
}
}
}
console.log('mySortArr', arr);
}
function fn(a, b) { return a - b }
sort(mySortArr, fn)
let slice = arr.slice(-2, -1);
console.log('arr', arr);
console.log('slice', slice);
console.log('arr', arr);
console.log('splice', arr.splice(1, 3, 'delete'));
console.log('arr', arr);
console.log('arr', arr);
console.log('find', arr.find(v => { return v > 6 }));
console.log('findIndex', arr.findIndex((v, i, arr) => { return v > 8 }));
console.log('findIndex-1', arr.findIndex((v, i, arr) => { return v > 100 }));
function f(v) {
return v > this.age;
}
let person = { name: 'John', age: 20 };
console.log([10, 12, 26, 15].find(f, person));
console.log([NaN].findIndex(v => Object.is(NaN, v)))
console.log('fill', [1, 2, 3].fill('5'));
console.log('fill', new Array(3).fill('6'));
['a', 'b', 'c'].fill(7, 1, 2)
for (let index of ['a', 'b'].keys()) {
console.log(index);
}
for (let elem of ['a', 'b'].values()) {
console.log(elem);
}
for (let [index, elem] of ['a', 'b'].entries()) {
console.log(index, elem);
}
arr.forEach((v, i, arr) => { console.log('forEach', v); })
let maparr = [1, 2, 3]
let map = maparr.map((v, i, arr) => { return v * v })
console.log('map', map);
console.log(maparr.map(Math.sqrt));
let filterarr = [12, 23, 14, 56, 34]
let newFilter = filterarr.filter((v, i, arr) => { return v > 18 })
console.log('newFilter', newFilter);
let some = ['a', 'b', 'c']
console.log('some', some.some((v, i, arr) => { return v = 'b' }));
let every = [12, 10, 29]
console.log('every', every.every((v, i, arr) => { return v > 20 }));
let reducearr = [12, 23, 14, 56, 34]
const Obj = reducearr.reduce((obj, v, i, arr) => { obj[i] = v; return obj }, {})
console.log('reduce', Obj);