-
Notifications
You must be signed in to change notification settings - Fork 0
18 Spread Operators
Biswajit Sundara edited this page Aug 18, 2023
·
1 revision
JavaScript ES6 (ECMAScript 6) introduced the spread operator. The syntax is three dots(...) followed by the array (or iterable*). It expands the array into individual elements.
const fruits = ["apple","mango","strawberry"];
const vegetables = ["brinjal","potato","tomato"];
const shopping = [...fruits,...vegetables];
shopping.forEach((item)=>{
console.log(item);
})
const uname = "Biswajit";
const letters = [...uname];
letters.forEach((letter)=>{
console.log(letter);
})
function addNumbers(n1,n2,n3){
return n1+n2+n3;
}
const numbers = [1, 4,6];
const addition = addNumbers(...numbers);
console.log(addition);