I like to use reduce when transforming lists, like creating a Map from an array based on a key:
constuserData=[{id:1,name:'A'},{id:2,name:'B'}];// a general-purpose array-to-map utilityconstarrayToMap=(list,idMapper)=>list.reduce((map,next)=>{map.set(idMapper(next),next);returnmap;},newMap());console.log(arrayToMap(userData,user=>user.id));
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I like to use
reduce
when transforming lists, like creating aMap
from an array based on a key: