Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
another one js array copy speed comparison
(version: 1)
Comparing performance of:
map vs array.from vs for loop vs foreach vs slice vs spread vs filter vs concat
Created:
5 years ago
by:
Registered User
Jump to the latest result
Tests:
map
const arr = [1,2,3,4,5] const newArr = arr.map(e=>e)
array.from
const arr = [1,2,3,4,5] const newArr = Array.from(arr)
for loop
const arr = [1,2,3,4,5] let newArr = []; for(let i = 0; i < arr.length; i++) { newArr[i] = arr[i]; }
foreach
const arr = [1,2,3,4,5] let newArr = [] arr.forEach(e => { newArr.push(e) })
slice
const arr = [1,2,3,4,5] const newArr = arr.slice()
spread
const arr = [1,2,3,4,5] const newArr = [...arr]
filter
const arr = [1,2,3,4,5] const newArr = arr.filter(() => true)
concat
const arr = [1,2,3,4,5] const newArr = [].concat(arr)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (8)
Previous results
Fork
Test case name
Result
map
array.from
for loop
foreach
slice
spread
filter
concat
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
JavaScript array copy methods for() vs spread operator
js array copy speed comparison v2
Cloning an array
js array copy speed comparison v3
js array copy speed comparison with spread
Comments
Confirm delete:
Do you really want to delete benchmark?