I am trying to use a function that works for two scenarios, it can either iterate through the key of an object in array or the array value itself. So this prints fine:
const arr1 = [{
car: 'audi'
},{
car: 'bmw'
}]
const printCars = arr1.map(({ car }) => console.log(car))
// audi
// bmw
But I dont know how to use the same function's default parameter to allow for a simple array
const arr2 = ['audi', 'bmw'];
const printCars = arr2.map(({ car }) => console.log(car));
// Obviously car is undefined
I wonder how can I do something like
const arr = ['audi', 'bmw'];
const printCars = arr.map(({ car } = car) => console.log(car));
// audi
// bmw