Perform Actions on all elements arrays(3)
Bernardo Aguayo Ortega
Senior Software Engineer @ ZeroCopyLabs | React & Next.js Specialist | Building Scalable Web Applications with JavaScript, TypeScript, and Node.js
There are a method incredible powerful call map that allow us to make transform in each element of the array.
//we have an array
const temperatures = [ { degrees: 69, isRecordTemp: false }, { degrees: 82, isRecordTemp: true }, { degrees: 73, isRecordTemp: false }, { degrees: 64, isRecordTemp: false }
]; //and suppose that we want to change Record Temp we want true in all of them, we can use map method const newTemps ? temperatures.map(temp =>{ temp.isRecordTemp = true return temp }) //return
const temperatures = [ { degrees: 69, isRecordTemp: true }, { degrees: 82, isRecordTemp: true }, { degrees: 73, isRecordTemp: true }, { degrees: 64, isRecordTemp: true }
]; // that change the value and return as new array
so map is very special and powerful array method.
There are other powerful array method call forEach basically is the same that map but don't return a new array, simple modify the elements and save in the same array.
I hope that you learned a new thing, with love Bernardo Aguayo