How to merge the corresponding parts of two object values in js

clipboard.png

clipboard.png

Mar.05,2021

you have to work hard!

//  obj 
let obj2 = Object.keys(obj).map(k => {
  return {
    name: obj[k],
    value: obj1[k]
  };
});

try the following code:

let a = { "a":"name", "b":"value"}
let b = { "a":123, "b":456}

let c={}
for (var key in a) {
    if (a.hasOwnProperty(key)) {
        console.log(key + " -> " + a[key]);
        console.log(b[key]);
        c[a[key]] =  b[key];
    }
}

console.log(c);

will output: "

a -> name
123
b -> value
456
{ name: 123, value: 456 }
Menu