Hi everyone, I am here again with tips on how to write easy simple and clean code.
Going forward I will state an example on how to practice the use of Spread Operator
Look at the code snippet below (using objects & arrays to shallow and copy)
const newObject = {}; Object.keys(oldObject).forEach((key) => { newObject[key] = oldObject[key]; }); const newArray =[]; oldArray.forEach((element) => { newArray.push(element); });
You can easily re-write that code in a much more simple way. Life will be much more easier for anyone reading your code.
const newObject = { ...oldOject }; const newArray =[ ...oldArray ];
Thanks for reading and happy coding.
SAM SONTER
Top comments (0)