Javascript 使用函数上的参数进行对象销毁
如果我有以下ES6方法:Javascript 使用函数上的参数进行对象销毁,javascript,arrays,function,object,ecmascript-6,Javascript,Arrays,Function,Object,Ecmascript 6,如果我有以下ES6方法: function myClothes([first, second, third]) { return { first: first, second: second, third: third } } 如何在控制台窗口中打印“运动鞋裤子衬衫”?我尝试了以下方法,但仍然缺乏解决方案: console.log(myClothes({ ['first']:'sneakers', ['second']:'pants', ['thi
function myClothes([first, second, third]) {
return {
first: first,
second: second,
third: third
}
}
如何在控制台窗口中打印“运动鞋裤子衬衫”?我尝试了以下方法,但仍然缺乏解决方案:
console.log(myClothes({
['first']:'sneakers',
['second']:'pants',
['third']:'shirt'
}));
我做错了什么
非常感谢 首先,将函数更改为使用对象分解。然后在函数中使用一个简单的
console.log
语句:
函数MyCloth({first,second,third}){
log([first,second,third].join(“”);
返回{
第一:第一,,
二:二,,
第三:第三
}
}
console.log(我的衣服)({
['first']:'sneakers',
['second']:'pants',
['third']:'shirt'
}));代码>
.as console wrapper{max height:100%!important;top:auto;}
@klewis因此对象是从函数返回的{first:“sneakers”}
位。使用[first,second,third]
的控制台.log
,您是否希望它们之间加入像运动鞋裤子衬衫这样的空格?@klewis我已经编辑了我的答案,现在对您有用吗?啊,我现在明白了。每次调用时,我都可以从函数内部打印到控制台,而不是从函数外部打印。加上我不知道加入。杰克,谢谢你给我上了这个课!没问题@klewis,总是很乐意帮忙。