1/* Copying arrays or parts of arrays in JavaScript */
2
3var fruit = ["apple", "banana", "fig"]; // Define initial array.
4console.log(fruit); // ["apple", "banana", "fig"]
5
6// Copy an entire array using .slice()
7var fruit2 = fruit.slice();
8console.log(fruit2); // ["apple", "banana", "fig"]
9
10// Copy only two array indicies rather than all three
11// From index 0 (inclusive) to index 2 (noninclusive)
12var fruit3 = fruit.slice(0,2);
13console.log(fruit3); // ["apple", "banana"]
1var ar = ["apple","banana","canaple"];
2var bar = Array.from(ar);
3alert(bar[1]); // alerts 'banana'
4
5// Notes: this is for in In ES6, works for an object of arrays too!
1var array1 = ['Hamburger', 'Fries']
2var array2 = ['Salad', 'Fruits']
3
4var combinedArray = array1.concat(array2); // => ['Hamburger', 'Fries', 'Salad', 'Fruits']
1// 1) Array of literal-values (boolean, number, string)
2const type1 = [true, 1, "true"];
3
4// 2) Array of literal-structures (array, object)
5const type2 = [[], {}];
6
7// 3) Array of prototype-objects (function)
8const type3 = [function () {}, function () {}];
9