reprahkcin
1/13/2019 - 3:33 AM

Combining arrays - The spread operator

const first = ["red", "green", "blue"];  // New array.
const second = [4,5,6]; // Different new array.

const combined = [...first, ...second]; // Third new array, populated by first and second arrays, in order.

combined.forEach(element => {    // forEach method of the array, mind the parentheses.
    console.log(element);        // Console will display indeces 0-6 "red, green, blue, 4, 5, 6," each on its own line.
});

console.log(combined);  // Console will display each element on the same line.







const first = { name: "Nick" };  // New object, with "name" property.
const second = { job: "Being Amazing", age: 37 }; // Different object, with "job" and "age" properties.

const combined = { ...first, ...second }; // Concatonate properties.
console.log(combined);

const truth = { ...first, is: "so cool!"};
console.log(truth);