I wanted to get values from one array of object with keys and values into another array of objects with the same keys.
const array1 = [{
key1: 7,
key2: 1,
key3: 37,
}];
const array2 = [
{
title: 'Some Title 1',
key: 'key1',
number: '',
icon: require('../../assets/some2.png')
},
{
title: 'Some Title 2',
key: 'key2',
number: '',
icon: require('../../assets/some1.png')
},
{
title: 'Some Title 3',
key: 'key3',
number: '',
icon: require('../../assets/some3.png')
},
];
I have tried using Object.keys to get all the keys from array1 object.
const keys = Object.keys(obj);
keys.map((key) => {
if (array2[key] === key) {
// console.log('card detail matching');
// add to the array 2 with value
}
})
but after a point its doesn't makes sense.
Expected array
const resultArray = [
{
title: 'Some Title 1',
key: 'key1',
number: 7,
icon: require('../../assets/some2.png')
},
{
title: 'Some Title 2',
key: 'key2',
number: 1,
icon: require('../../assets/some1.png')
},
{
title: 'Some Title 3',
key: 'key3',
number: 37,
icon: require('../../assets/some3.png')
}
]
I expect the output to be the values of the key would be entered in array2 in the 'number' key.