var arr = [];
for (var i = 0; i < 100; i++) {arr.push(Math.random());}
for (var j = 0; j < 1000; j++) {while (arr.length > 0) {arr.pop(); // this executes 100 times, not 100000}}
mainArr = []; // a new empty array is addressed to mainArr.
var arr = new Array('10'); // Array constructorarr.unshift('1'); // add to the frontarr.push('15'); // add to the endconsole.log("After Adding : ", arr); // ["1", "10", "15"]
arr.pop(); // remove from the endarr.shift(); // remove from the frontconsole.log("After Removing : ", arr); // ["10"]
var arrLit = ['14', '17'];console.log("array literal « ", indexedItem( arrLit ) ); // {0,14}{1,17}
function indexedItem( arr ) {var indexedStr = "";arr.forEach(function(item, index, array) {indexedStr += "{"+index+","+item+"}";console.log(item, index);});return indexedStr;}
slice() : By using slice function we get an shallow copy of elements from the original array, with new memory address, So that any modification on cloneArr will not affect to an actual|original array.
var shallowCopy = mainArr.slice(); // this is how to make a copy
var cloneArr = mainArr.slice(0, 3);console.log('Main', mainArr, '\tCloned', cloneArr);
cloneArr.length = 0; // Clears current memory location of an array.console.log('Main', mainArr, '\tCloned', cloneArr);