Array copy

Benchmark created on


Setup

const array = [...Array(100000)].map(() => Math.random())

Test runner

Ready to run.

Testing in
TestOps/sec
Array.from
const copy = Array.from(array)
ready
array.slice
const copy = array.slice()
ready
Spread operator
const copy = [...array]
ready
For loop assign
const copy = []

for (i = 0; i < array.length; i++) {
  copy[i] = array[i]
}
ready
For loop push
const copy = []

for (i = 0; i < array.length; i++) {
  copy.push(array[i])
}
ready
For of loop push
const copy = []

for (const item of array) {
  copy.push(item)
}
ready
array.map
const copy = array.map((item) => item)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.