I have an array of object which consists some id's as a key.
const sampleObj1 = {0011:[{},{}], 0022:[{}, {}], 0033:[{},{}]}
const sampleObj2 = [{id:0011, name:'test1'}, {id:0022, name:'test2'}, {id:0033, name:'test3'}]
I want to compare sampleObj1 key with the sampleObj2 id value and then need to create new obj some like below.
const newObjByComparing = {test1:[{},{}], test2:[{},{}], test3:[{},{}]} //desired result
I have tried using for loop but not able to get the desired compared value.
const fromRdx = sampleObj2;
const fromApi = sampleObj1;
const keys = Object.keys(fromApi);
const newObjAfterComparision = {};
for (let i in fromRdx) {
newObjAfterComparision[fromRdx[i]] = fromApi[keys[i]];
fromApi[fromRdx[i]] = fromApi[keys[i]];
delete fromApi[keys[i]];
}
console.log(newObjAfterComparision)