React Native

React native - 컬렉션 변환

Machine_웅 2023. 2. 2. 09:52
728x90
반응형

List to Map 

// List to Map
const arrMap = result.reduce((map, obj) => {
   map.set(obj.code.split(' ').join(''), obj.locationName);
   return map;
}, new Map)

 

List to Obj 

const arrObj = array.reduce((newObj, obj) => {
    newObj[obj.key] = obj.value;
    return newObj;
}, {});
console.log(arrObj);
728x90
반응형