1const names = ['Alex', 'Bob', 'Johny', 'Atta'];
2
3// convert array to th object
4const obj = Object.assign({}, names);
5
6// print object
7console.log(obj);
8
9// {0: "Alex", 1: "Bob", 2: "Johny", 3: "Atta"}
10
1const object1 = {
2 a: 'somestring',
3 b: 42,
4 c: false
5};
6
7console.log(Object.keys(object1));
8// expected output: Array ["a", "b", "c"]
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}, {});