I'm trying to use destructuring on elements of my subItems array to get variables that refer directly to the links and open properties.
Specifically, I'm trying to use the following code, which fails as specified in the comments.
const [{links, open}] = subItems.map(({ items }) => {
document.getElementById(items);
}); // Fails: returns nothing
const {links, open} = subItems((items ) => {
return items;
}); // Fails: returns only the first `link` and `open`
// This is what the `subItems` array looks like:
export const subItems = [
{
links: [
{ title: 'ret', to: '#' },
{ title: 'def', to: '#' },
{ title: 'rev', to: '#' },
{ title: 'red', to: '#' },
{ title: 'im', to: '#' },
{ title: 'glossar', to: '#' }
],
open: true
},
{
links: [
{ title: 'recloud', to: '#' },
{ title: 'broker', to: '#' },
{ title: 'mercury', to: '#' },
{ title: 'investor', to: '#' }
],
open: false
}
];
P.S. I'm new to JS, sorry if I'm misunderstanding something trivial.
linksandopendo you want? There are two, one set at index 0 and another set at index 1. Or do you want an array of just those? Or...?linkproperties to one varaible? Something like this: Destructure object properties inside array for all elements and How to destructure an array of objects?subItems.map(({link, open})=>{ })