In the method comes two arrays of array1(id1...idn) array 2(aelem1...elemn) .
How to make a new type of them
Obj = { array1[I]: array2[j] } for example
Obj = { Id1: elem1, Id2: elem2, Id3: elem3, ... } In the method comes two arrays of array1(id1...idn) array 2(aelem1...elemn) .
How to make a new type of them
Obj = { array1[I]: array2[j] } for example
Obj = { Id1: elem1, Id2: elem2, Id3: elem3, ... } var keys = ['foo', 'bar', 'baz']; var values = [11, 22, 33] var result = {}; keys.forEach((key, i) => result[key] = values[i]); console.log(result); var arr1 = ["id1", "id2", "id3"]; var arr2 = ["elem1", "elem2", "elem3"]; var obj = {}; for(var i = 0; i < arr1.length; i++) { obj[arr1[i]] = arr2[i]; } console.log(obj); For a change
function Fu_0001(_arr, _markerKey){ if(_arr.length){ this[(_markerKey || "") + _arr.length] = _arr.pop() this.constructor.apply(this, Array.prototype.slice.call(arguments)); } } console.log(new Fu_0001(["elem1", "elem2", "elem3"],"Id")) var arr1 = ["id1", "id2", "id3"]; var arr2 = ["elem1", "elem2", "elem3"]; var obj = arr1.reduce(function(map, x, idx){ map[x] = arr2[idx]; return map; }, {}); Source: https://ru.stackoverflow.com/questions/755204/
All Articles