const arr = [
{
name: 'test1',
koef: 1,
id: 1,
age: 23
},
{
name: 'test2',
koef: 1,
id: 2,
age: 23
},
{
name: 'test3',
koef: 2,
id: 3,
age: 23
},
{
name: 'test4',
koef: 2,
id: 4,
age: 23
},
{
name: 'test5',
koef: 3,
id: 5,
age: 23
},
{
name: 'test6',
koef: 3,
id: 6,
age: 23
},
];
const createMap = (array, key) => new Map(array.map(entry => [entry[key], entry]));
const map = createMap(arr, 'name');
console.log(map);
/*
Map(6) {
'test1' => { name: 'test1', koef: 1, id: 1, age: 23 },
'test2' => { name: 'test2', koef: 1, id: 2, age: 23 },
'test3' => { name: 'test3', koef: 2, id: 3, age: 23 },
'test4' => { name: 'test4', koef: 2, id: 4, age: 23 },
'test5' => { name: 'test5', koef: 3, id: 5, age: 23 },
'test6' => { name: 'test6', koef: 3, id: 6, age: 23 }
}
*/
map.get('test6').koef = map.get('test1').koef;
console.log(map);
/*
Map(6) {
'test1' => { name: 'test1', koef: 1, id: 1, age: 23 },
'test2' => { name: 'test2', koef: 1, id: 2, age: 23 },
'test3' => { name: 'test3', koef: 2, id: 3, age: 23 },
'test4' => { name: 'test4', koef: 2, id: 4, age: 23 },
'test5' => { name: 'test5', koef: 3, id: 5, age: 23 },
'test6' => { name: 'test6', koef: 1, id: 6, age: 23 }
}
*/