Skip to content
Advertisement

Tag: grouping

Javascript Grouping by object property, when property is an array

I currently have an array of items that looks a bit like this: I want to group the items by category lookup, with the slight problem that category lookup is potentially an array, such that Parent Item 2 would be listed twice (once in My Cat) and once in something else) I tried using https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/groupBy but it doesn’t seem to

Dynamically group flattened JSON into nested JSON object

Suppose I have the following JSON array: And would like to convert it into the following multidimensional object in JavaScript (no Lodash): I figure I can do it with a foreach, but I’m trying to do it using the reduce function (HOPING that is the right one to use here) and just not getting the right syntax. My current GUESS

Advertisement