Sunday, November 28, 2021

Spread operator in javascript

 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

Element of a good table (Ref: Database design mere mortals by Michael J. Hernandez)

  Elements of the Ideal Table: It represents a single subject, which can be an object or event that reduces the risk of potential data integ...