Skip to content

What is the time complexity of object spread operator in Javascript?

I found that there are some QAs about spread operator time complexity but those are all for array.

Is the spread operator time complexity same for object?

a = { ...b }

What is the time complexity of the above statement if the key count of b is N?

is it O(N)?



It’s O(n). Object spread iterates through all enumerable own properties and assigns them to a new object, and property assignment is an O(1) process. If there are N keys to iterate through, there are around N such operations to perform.

That said, this here will not be a bottleneck in 99.9% of actual code, so it’s not worth worrying about.