Create a shallow copy of an array

Benchmark created on


Setup

const data = ['1', 'two', 3, true]

Test runner

Ready to run.

Testing in
TestOps/sec
Spread operator
const copy = [...data]
ready
JSON
const copy = JSON.parse(JSON.stringify(data))
ready
slice()
const copy = data.slice()
ready
map()
const copy = data.map(item => item)
ready
forEach() + push()
const copy = []
data.forEach(item => copy.push(item))
ready

Revisions

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