JS -Array, um mit Schlüssel zu gestalten
const arr = ['a','b','c'];
const res = arr.reduce((a,b)=> (a[b]='',a),{});
console.log(res)
Sleepy Squirrel
const arr = ['a','b','c'];
const res = arr.reduce((a,b)=> (a[b]='',a),{});
console.log(res)
const convertArrayToObject = (array, key) =>
array.reduce(
(obj, item) => ({
...obj,
[item[key]]: item
}),
{}
);
let arr = [{a: 'a', b: 1, c: 'c'}, {a: 'a', b: 2, c: 'c'}, {a: 'a', b: 3, c: 'c'}]:
let mapped = arr.reduce (function (map, obj) {
map[obj.b] = obj;
return map;
},{}); // reduce
console.log (mapped); // {1: {a: 'a', b: 1, c: 'c'}, 2: {a: 'a', b: 2, c: 'c'}, 3: {a: 'a', b: 3, c: 'c'}
const subLocationTypes = (location.subLocationTypes || []).reduce((add, cur) => {
add[cur.key] = cur.value;
return add;
}, {});