Spread operator introduced in ES6.The syntax is three dot(...variable name). It expands the array into individual elements.We can use to insert any element into any position in a array .
ex:
const familyLokman=['lokman','muna','tutul'];
const familySohel=['sohel','ruma','imran'];
const familyBig=[...familyLokman,...familySohel];
console.log(familyBig);
here,familyLokman and familySohel is two array .No we want to merge it into one array then we can use spread operator.
we can use spread operator for dom nodes too.
const h = document.querySelector('h1');//h1 is the dom element with no class name and id .only tag name
const boxes=document.querySelector('.boxes');//boxes is the class name which return nodeslist
const all=[h,...boxes];//add all node to all array
Array.from(all).foreach(el=>//Array.from(all) converting node list into an array
el.style.color='purple');
No comments:
Post a Comment