const list = [
{ label: "javascript", color: "blue" },
{ label: "html", color: "red" },
{ label: "css", color: "green" },
];
const initialValue = {};
const convertToObject = (result, item) => {
const language = item.label;
const color = item.color;
return {
...result,
[language]: color,
};
};
const palette = list.reduce(convertToObject, initialValue);
console.log(palette); // { javascript: 'blue', html: 'red', css: 'green' }
Thanks for reading π
Follow @codedrops.tech for daily posts.
Instagram β Twitter β Facebook
Micro-Learning β Web Development β Javascript β MERN stack β Javascript
codedrops.tech
Top comments (3)
Hi Melissa, I'm going to try to explain to you what's happening in that part of the code.
I hope you have understood me!
You're welcome, I'm also starting in web development. If you have any other questions, let me know.
Thanks Mauro for the explanation