Seeking to combine objects with the same key within an array of objects.
The initial object structure is as follows:
const cultures = {
"en-us": {
"path": "/en/playground/copy/",
"startItem": {
"id": "8cd7943c-1ba5-41cb-a9ac-7435fbdb1458",
"path": "path"
}
},
"da-dk": {
"path": "/playground/copy/",
"startItem": {
"id": "8cd7943c-1ba5-41cb-a9ac-7435fbdb1458",
"path": "path"
}
}
}
Next, the array of objects looks like this:
const lang = [
{
name: 'English',
isoCode: 'en-us',
url: '/en/'
},
{
name: 'Danish',
isoCode: 'da-dk',
url: '/'
}
]
The goal is to extract the path from the first object and merge it into the array of objects by matching keys. Is there a way to achieve this?
[
{
name: 'English',
isoCode: 'en-US',
url: '/en/',
path: "/en/playground/copy/",
},
{
name: 'Danish',
isoCode: 'da-DK',
url: '/',
path: "/playground/copy/",
}
]
An attempt was made using the following code snippet but it consistently returns false:
languages.filter((item, i) => {
const arr = [];
const result = item.isoCode === data.cultures[item.isoCode];
arr.push(result);
});