As the comment from Mark Meyer says, arrays are objects.
Specifically an array is an object whose keys are strings representing small integers. There is some magic to handle how length
is updated as values are added or removed and how values are removed as length
is updated. Other than that, it's an Object at its core.
So in this code (please include such code in your question rather than pointing to an external site):
var a = ['a','b','c'];
var b = Object.assign([], a, ['x']);
all that happens is that it takes the initial value passed, []
and then adds the properties from a
onto it, the properties whose keys are '0'
, '1'
, and '2'
, with respective values of 'a'
, 'b'
, and 'c'
, then adds the properties from ['x']
onto it, the only one being key '0'
with value 'x'
, yielding ['x', 'b', 'c']
.
So it's simple object handling.
Note that if you did
Object.assign([], a, [, 'x']);
you would get ['a', 'x', 'c']
, and if you did
Object.assign([], a, [, , , , 'x']);
you would get ["a", "b", "c", undefined, "x"]