Reputation: 1760
I have next map:
const filter = new Map();
filter.set('a1', {
Day: 55,
Type: 1,
});
filter.set('a2', {
Day: 2,
Type: 3,
});
and I want to iterate thru it, by extracting only objects:
filter.values().map(({ Day, Type }) => {
console.log(Day)
});
or
[...filter].map(({ Time, Type }) => {
console.log(eventTime)
});
but I am getting error that map() is not function, or for second case it return Map item
p.s. I can't use for loops.
Upvotes: 0
Views: 64
Reputation: 122047
To get and array of objects you can use spread syntax ...
on map values that returns MapIterator
. Then you can use any array method like forEach
.
const filter = new Map();
filter.set('a1', { Day: 55, Type: 1 });
filter.set('a2', { Day: 2, Type: 3 });
console.log([...filter.values()])
Upvotes: 0
Reputation: 996
const filter = new Map();
filter.set('a1', {
Day: 55,
Type: 1,
});
filter.set('a2', {
Day: 2,
Type: 3,
});
for ( {Day,Type} of filter.values()) {
console.log("Day: ",Day, "Type:",Type)
}
Upvotes: 1