I'm writing a complex recursive function which working with array of objects which includes each other.
For example, I have an object, like this one:
let item = {
name: "Test",
key: "value",
pricing_methods: [ [Objects], [Objects] ] //array of object
}
where pricing_methods
value is array of arrays, with array of objects inside:
[
[
{ key: 'CONST', count: 1, reagent_items: [ {Object}, {Object} ] },
{ key: 'COMMDTY', count: 1, reagent_items: [ {Object}, {Object} ] }
],
[
{ key: 'CONST', count: 2, reagent_items: [ {Object}, {Object} ] },
{ key: 'COMMDTY', count: 1, reagent_items: [ {Object}, {Object} ] },
...
],
[
...
]
]
and as you may already guesses this reagent_items
is array of objects/items from the beginning which also have it's own pricing_methods
and so on...
If you have seen Christopher's Nolan «Inception» Movie it's some-kind like that.
THE PROBLEM
So as you may already saw I need to work with arrays of objects and it's properties. So here is my question:
What's the optimized or universal practice,
npm module
/ library for such operations as remove/add/group/unwind an object inside array based on object's value?
Especially I needed group/unwind operations for object values inside array, how to achieve from:
[
{ key: 'CONST', count: 1, reagent_items: [ {Object}, {Object} ] },
{ key: 'COMMDTY', count: 1, reagent_items: [ {Object}, {Object} ] }
]
this one:
[
{
name: "reagent_items#1",
all_keys: "all_values#1",
key: 'CONST',
},
{Object}, //all items for CONST and COMMDTY keys combined.
{
name: "reagent_items#2",
all_keys: "all_values#2",
key: 'COMMDTY',
}
]
- Should I define my own
class
for every item/pricing_method with getters/setters - Define my own
array.method
, likearray.GroupByValue()
- Or it's better to use
lodash
or_underscore
or any other library which provides same methods like this?
P.S. I don't know all capabilities of lodash
or any other array library so any advice will be helpful.