1let arr = [{a: 'a', b: 1, c: 'c'}, {a: 'a', b: 2, c: 'c'}, {a: 'a', b: 3, c: 'c'}]:
2 let mapped = arr.reduce (function (map, obj) {
3 map[obj.b] = obj;
4 return map;
5 },{}); // reduce
6console.log (mapped); // {1: {a: 'a', b: 1, c: 'c'}, 2: {a: 'a', b: 2, c: 'c'}, 3: {a: 'a', b: 3, c: 'c'}
1const convertArrayToObject = (array, key) =>
2 array.reduce(
3 (obj, item) => ({
4 ...obj,
5 [item[key]]: item
6 }),
7 {}
8 );
9
1const arr = ['a','b','c'];
2const res = arr.reduce((a,b)=> (a[b]='',a),{});
3console.log(res)
1const subLocationTypes = (location.subLocationTypes || []).reduce((add, cur) => {
2add[cur.key] = cur.value;
3return add;
4}, {});