If I have the following ES6 method:
function myClothes([first, second, third]) {
return {
first: first,
second: second,
third: third
}
}
How do I print out "sneakers pants shirt" in my console window? I have tried the following but I am still short of a solution:
console.log(myClothes({
['first']:'sneakers',
['second']:'pants',
['third']:'shirt'
}));
What am I doing wrong?
Many thanks!
Firstly, change your function to use object destructuring. Then use a simple console.log
statement inside the function:
function myClothes({first, second, third}) { console.log([first, second, third].join(" ")); return { first: first, second: second, third: third } } console.log(myClothes({ ['first']:'sneakers', ['second']:'pants', ['third']:'shirt' }));
.as-console-wrapper { max-height: 100% !important; top: auto; }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.