Create a shallow copy of an object

Benchmark created on


Setup

const data = {
	a: '1',
	b: 'two',
	c: 3,
	d: 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
Object.assign()
const copy = Object.assign({}, data)
ready
for
const copy = {}
for (let i in data) {
    copy[i] = data[i]
}
ready

Revisions

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