Is there a way to destructure the "First shop" value in one go from this array?
const myArr = [
{
name: 'John',
age: '28',
hobbies: ['coding', 'chess', 'cards', 'reading'],
address: {
city: 'Some city',
province: 'Some province',
country: 'Some country',
},
places: {
coffeeShops: ['First shop', 'Second shop', 'Third shop'],
},
},
];
Extracting the object from the array first actually works but I want to destructure from the array itself.
This works:
const obj = myArr[0];
const {
places: {
coffeeShops: [first],
},
} = obj;
console.log(first);
But I can't seem to do it when the object is inside the array. Is that possible in JS?
first) out of an array positionally, did you try applying that to the rootmyArrtoo?const [ { places: { coffeeShops: [x], }, }, ] = myArr;