javascript - es6 problem of converting class array into array
扔个三星炸死你
扔个三星炸死你 2017-06-30 09:55:43
0
3
717

Chestnut:
var a = {'1':'gg','2':'love','4':'meimei',length:5};
var arr=[.. .a];
console.log(arr);

Error reported under Google Chrome: Uncaught TypeError: a[Symbol.iterator] is not a function

Definition of array-like:/a/11...

javascript introduction documentation on ‘...’: https://developer.mozilla.org...

The official JavaScript documentation says that '...' can convert a class array into an array. Why does it still report an error? confuse!

扔个三星炸死你
扔个三星炸死你

reply all(3)
伊谢尔伦

You should read the article you posted carefully first.

The reason why it is called "array-like" is because it is similar to "array". You cannot use array methods directly, but you can use array-like methods just like arrays.

You cannot use the array method directly. Isn’t your extension statement used directly?

You need to convert the class array into an array first, you can use Array.prototype.slice.call(arguments)

introduced in the article

ES6 also has a method, Array.from(arrayLike)

習慣沉默

Please use Array.from()

If you look at the English page, you will find that the expanded object needs to be traversable

Only for iterables

Spread syntax can be applied only to iterable objects:

var obj = {'key1': 'value1'};
var array = [...obj]; // TypeError: obj is not iterable
滿天的星座

ES6 has so many new features, do you expect the browser to implement them all?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template