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
Latest comments (3)
You're welcome, I'm also starting in web development. If you have any other questions, let me know.
Thanks Mauro for the explanation
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!