The spread operator ...
, introduced first in ES6 became one of the most popular and favourite feature among the developers.
This tutorial describes how to add an element to the ending of an array using spread operator in ES6
Example with animals emoji
let animals = ["๐ฆ", "๐ต", "๐", "๐ฆ", "๐ฏ"];
console.log(animals);
// Output โ ["๐ฆ", "๐ต", "๐", "๐ฆ", "๐ฏ"]
console.log(animals.length);
// Output โ 5
animals = [...animals, "๐ฆ"];
console.log(animals.length);
// Output โ 6
console.log(animals);
// Output โ ["๐ฆ", "๐ต", "๐", "๐ฆ", "๐ฏ", "๐ฆ"]
Read the complete post on our site MeshWorld - How to add an element to ending of an array with ES6
Happy coding
Top comments (0)