, .
const myMap = {
"1G7JA": {
id: 1,
name: "Jack"
},
"H7GA0": {
id: 2,
name: "Betty"
},
"8JK12": {
id: 3,
name: "Mary"
}
};
const myArray = Object.values(myMap).filter(report=> report.user._id === userId);
const arrayToMap = (array, element) => {
const result = {};
array.forEach(item => {
result[Object.byString(item, element)] = item;
});
return result;
};
However, you convert the map into an array (lots of processing) that is easy to filter. It is counterproductive to use only on small arrays, where the need to save your list as an object weighs a good reason to use it.
Yours faithfully
Daniel
source
share