对象的展开运算符 (...
) 不起作用,您可以在下面的代码中看到。这是预期的行为吗?
在 jsbin 中尝试
//var test ={start:'stating',end: 'ending'}; //its not working
var test=['start-value','end-value']; //its working
function display(start,end){
console.log(start,end);
}
display(...test)
问这个问题的原因是,我在下面的代码行中看到了使用对象的扩展运算符的使用,但它对我不起作用。
我是否缺少任何配置以使其正常工作?
最佳答案
来自文档:
Only for iterables
Note that the spread operator can be applied only to iterable objects:
var obj = {'key1': 'value1'};
var array = [...obj]; // TypeError: obj is not iterable
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator
关于对象的 javascript 传播运算符不起作用?这是预期的行为吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43209119/