How can I transform a big object
to array
with lodash?
var obj = {
22: {name:\"John\", id:22, friends:[5,31,55], works:{books:[],
If you want some custom mapping (like original Array.prototype.map) of Object into an Array, you can just use _.forEach
:
let myObject = {
key1: "value1",
key2: "value2",
// ...
};
let myNewArray = [];
_.forEach(myObject, (value, key) => {
myNewArray.push({
someNewKey: key,
someNewValue: value.toUpperCase() // just an example of new value based on original value
});
});
// myNewArray => [{ someNewKey: key1, someNewValue: 'VALUE1' }, ... ];
See lodash
doc of _.forEach https://lodash.com/docs/#forEach