We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Shallow clone an array.
Alternatives: shallowClone, deepClone.
function shallowClone(x) // x: an array
const xarray = require('extra-array'); var x = [1, 2, 3, [4, 5]]; var y = xarray.shallowClone(x); // → [ 1, 2, 3, [ 4, 5 ] ] (y shallow cloned) y[1] = 0; y; // → [ 1, 0, 3, [ 4, 5 ] ] (y modified) x; // → [ 1, 2, 3, [ 4, 5 ] ] (x not modified) y[3][0] = 0; y; // → [ 1, 0, 3, [ 0, 5 ] ] (y modified) x; // → [ 1, 2, 3, [ 0, 5 ] ] (x modified)