Created
July 13, 2022 13:00
-
-
Save Shaxadhere/9ca5ea80e007a5861d2fcc50fceb3091 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const categories = [ | |
{id:1, name:"Web Design"}, | |
{id:2, name:"Web Development"}, | |
{id:3, name:"Logo Design"} | |
] | |
const data = [ | |
{id:1, title:"Some title", category: "Web Design"}, | |
{id:1, title:"Some title", category: "Some new"}, | |
{id:1, title:"Some title", category: "Web Design"}, | |
{id:1, title:"Some title", category: "Web Design"}, | |
] | |
const newData = data.map((item) => { | |
const status = categories | |
.map((_) => _.name) | |
.includes(item.category) | |
if(status){ | |
return item | |
} | |
else{ | |
const _item = {...item, category: "Uncategorized"} | |
return _item | |
} | |
}) | |
console.log(newData) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment