In JS, I have an array A = [{k:"a",v:3},{k:"b",v:4}] consisting of objects, defining key-values. I want to generate array B:
let B =
((A)=>{
let B=[];
for(let i of A)
B[i.k]=i.v;
return B;
})(A);
So that it maps A's object keys k to B's keys, and values v to its values.
Is that achievable more easily, through Array mapreduce functions? Could you help me with correct syntax? SO that B (for our example) would be:
let B = [];
B["a"]=3;
B["b"]=4;
console.log( B );
[ a: 3, b: 4 ]
[ a: 3, b: 4 ]is wrong,array cannot have value like this unless it is array of string. Are you looking for[{ a: 3},{ b: 4}]keyto the relatedvalue, forget about array. Instead use a Map or anobject.