social
//push and pop
var testArray = [];
for(var i = 10;i>=0;i++){
testArray.push(i)
}
console.log(testArray);
testArray.reverse();
console.log(testArray)
for(var i=10;i>=0;i++){
testArray.pop();
}

testArray = new(10);
testArray.length;

//slice and splice
testArray = new Array(1,2,3,4,5);
console.log(testArray);
var indexOf = testArray.indexOf(5);
console.log(\'indexOf 5 is \' + indexOf);
indexOf= testArray.lastIndexOf(3);
console.log(\'lastIndexOf 3 is \' + indexOf);
var slicedArray = testArray.slice(1,2);
console.log(\'sliced array: \' + slicedArray );
console.log(testArray);
testArray.splice(0,4);
console.log(\'after splice: \' + testArray);

 

分类:

技术点:

相关文章: