先上图:
代码演示:
var arr=[]; arr.push('tom','james','alen','peter'); console.log(arr.length);
//这里toString()一下,不然用console.log()就看不到效果了
console.log(arr.toString());
console.log('----------------'); //pop console.log('pop:'+arr.pop()); console.log(arr.length); console.log(arr.toString()); console.log('----------------'); //shift console.log('shift:'+arr.shift()); console.log(arr.length); console.log(arr.toString()); console.log('----------------'); //unshift console.log('unshift:lily,lucy'); arr.unshift('lily','lucy'); console.log(arr.length); console.log(arr.toString()); console.log('----------------'); //shift console.log('shift:'+arr.shift()); console.log(arr.length); console.log(arr.toString());