eslint-plugin-array-func
eslint-plugin-array-func copied to clipboard
Prefer slice for copying arrays
Array.from etc. are probably slower. Need to investigate.
Made a little test case for peace of mind: https://jsperf.com/array-cloning-freak/1
The ranking is as follows (checked in Chromium and Firefox, so we have V8 and SpiderMonkey):
-
Array.prototype.slice
-
Reflect.construct(Array
-
Array.prototype.map
(performs better than Reflect.construct in SpiderMonkey) - Everything else, like spreading or
Array.from
... (far slower)
This should actually be a rule where the user can choose their preferred method.