Created
March 29, 2020 16:32
-
-
Save jackbillstrom/8d356dbcfb51b67a01c3652e64b5b16b 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
var data = [{ | |
id: 7485, | |
name: "Klädseltvätt", | |
categories: [{ | |
id: 189, | |
name: "Tjänster", | |
slug: "services" | |
}, { | |
id: 207, | |
name: "Rekond", | |
slug: "rekond" | |
}] | |
}, { | |
id: 7456, | |
name: "Hankook Kinergy Eco 2 K435 185/60-14 H", | |
categories: [{ | |
id: 28, | |
name: "Sommardäck", | |
slug: "sommardack" | |
}] | |
}] | |
let computed = data.filter((group) => { | |
let _name | |
let _group = [] | |
let _temp | |
if(group.categories.map((item)=>{ | |
_name = item.name | |
_temp = group.name | |
debugger | |
_group.push(group) | |
return item | |
}).length>0){ | |
group.name = _name | |
group.products = _group | |
return group | |
debugger | |
} | |
}) | |
console.log(computed) |
Author
jackbillstrom
commented
Apr 4, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment