Skip to content

Instantly share code, notes, and snippets.

@Shaxadhere
Created July 13, 2022 13:00
Show Gist options
  • Save Shaxadhere/9ca5ea80e007a5861d2fcc50fceb3091 to your computer and use it in GitHub Desktop.
Save Shaxadhere/9ca5ea80e007a5861d2fcc50fceb3091 to your computer and use it in GitHub Desktop.
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