Slide 19
Slide 19 text
Modifying arrays
Elements can be added to arrays using the index or
push method. Using the concat method results in a
new array.
var arr = [0, 1, 2];
arr[arr.length] = 3;
console.log(arr);
>> [0, 1, 2, 3]
arr.push(4);
console.log(arr);
>> [0, 1, 2, 3, 4]
arr.pop();
console.log(arr);
>> [0, 1, 2, 3]
var newArr = arr.concat(5, 6);
console.log(newArr);
>> [0, 1, 2, 3, 5, 6]