I am taking a course where instructor used a number lines of code like below:
const ingredients = {
salad: 1,
bacon: 1,
cheese: 2,
meat: 2
}
// then he uses Object.keys method and mapped it like this:
Object.keys(ingredients) // this line provide ['salad', 'bacon', 'cheese', 'meat']
.map(igKey =>{
return [...Array(ingredients[igKey])] // Confused Line
**// above line provide**
//[undefined]
//[undefined]
//[undefined, undefined]
//[undefined, undefined] //I am confused :( how this line works!
.map((_, i) => {
// here return something.
}
));
The Confused Line take igKey = 'salad' return one undefined value as same as it takes igKey = 'cheese' and return two undefined value; it doesn't take the value of 'salad' or 'cheese' as argument but how does it return as times as it's value?
please someone help to understand this line of code [...Array(ingredients[igKey])];