3 ms·
Imagine this: a = new Array(10); b = [10]; alert(a[0]); alert(b[0]); Do you know the difference? This is just one reason. Also [] will be faster. Just goo
by odabaxok 11y ago
Imagine this:
a = new Array(10);
b = [10];
alert(a[0]);
alert(b[0]);
Do you know the difference?
This is just one reason. Also [] will be faster. Just google the differences and why [] is recommended to use.
- ahoge 11y ago> new Array('a') ["a"] > new Array(2, 3) [2, 3] > new Array(2) [undefined, undefined] > new Array(2.3) RangeError: invalid array length > new Array(2.3, 4.5) [2.3, 4.5] The Array constructor is really bogus. It switches to a different mode if a single number is passed. ES6 added `Array.of` for this reason: > Array.of() [] > Array.of(1) [1] > Array.of(1, 2) [1, 2] I don't really think it's needed though. Spread and rest already take care of the common use cases.