const number = [1,4,7,3,6];
const number2 = [9,8];
console.log('删除数组中的第一个元素输出结果4,7,3,6', number.shift(),number);
console.log('删除数组中最后一个元素输出结果 7,3',number.pop());
console.log('在数组最开始插入数据', number.unshift(1));
console.log(number.concat(number2));
console.log(number2.reverse());
console.log(number2.join('-'));
const array1 = number.filter(function (value, index) {
console.log(value,index);
return value !== 1;
});
console.log(array1);
const array2 = number.map(function (value,index) {
return value*2;
});
console.log(array2);
number.forEach(function (value,index) {
console.log(value);
})
var arr = [1,2,4,4,3,3,1,5,3];
function res(arr) {
var tmp = [];
arr.sort().sort(function (a,b) {
console.log(a,b);
if(a === b && tmp.indexOf(a) === -1){
tmp.push(a)
}
})
return tmp
}
var result = res(arr);
console.log(result )
网友评论