I was just wondering the best way to approach this in JavaScript using ES6.
Using the following data:
categories: [
{id: 1,name: "category 1",items: [19993, 99737]},
{id: 2,name: "category 2",items: [70264, 65474, 07078]},
{id: 3,name: "category 3",items: [76765]}
]
items: [
{id: 19993, name: "item 1"},
{id: 70264, name: "item 2"},
{id: 99737, name: "item 3"},
{id: 65474, name: "item 4"},
{id: 76765, name: "item 5"},
{id: 07078, name: "item 6"}
]
I'm trying to create a new array of items for each category, based on the ID's included in the categories.items array.
So for category 1 the output should be:
[
{id: 19993, name: "item 1"},
{id: 99737, name: "item 3"}
]
I know I can do this with a mess of loops, pushing into an array but was wondering if there was an shorter ES6 way of achieving this?
Thanks