Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
How do I access new Map() keys and values with .get()

I have Function that maps out an Array in to Groups and now I want to access the keys and values in the groups

toDoList Array

Code to group array with new Map()

reduceArray() {
  console.log("this.toDoList", this.toDoList);
  const MapArrayIntoGroups = this.toDoList.reduce(
    (Map, e) => Map.set(e.ID, [...Map.get(e.ID)||[], e]),
    new Map()
  );
  console.log("MapArrayIntoGroups",MapArrayIntoGroups);
  const key = MapArrayIntoGroups.get(); // get Key
  console.log("key",key);
  const value = MapArrayIntoGroups.get(); // value array
  console.log("value",value);
}

Here is the result

result of mapping

I have trying MapArrayIntoGroups.get(value); etc.. with no success. How do I access those keys, values

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can iterate your map with for of:

for (const [key, value] of MapArrayIntoGroups) {
  console.log(key)
  console.log(value)
}

or forEach:

MapArrayIntoGroups.forEach(function(value, key) {
  console.log(key)
  console.log(value)
}
about 4 years ago · Juan Pablo Isaza Report

0

Instead of

const key = MapArrayIntoGroups.get(); // get Key
console.log("key",key);
const value = MapArrayIntoGroups.get(); // value array
console.log("value",value);

Do like that to get the value if you know the key

const key = 1496
const value =MapArrayIntoGroups.get(key);

How do I access those keys, values

//utility function to get keys of each entry
const keys = arrays => arrays.map(array=>array[0]);

// keys([...MapArrayIntoGroups]);// try this to get all keys like an array [1496,...]

Thanks @Heretic said in comments that map has Already a method called keys(); Which is self-explanatory get all keys of an map

Array.from(MapArrayIntoGroups.keys());
//or
[...MapArrayIntoGroups.keys()];
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!