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.