Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

To explain on comment
Source Link
Arghya C
  • 10.1k
  • 4
  • 51
  • 70

With ES6+ you can simply do this

const original = [1, 2, 3];
const newArray = [...original];

The documentation for spread syntax is here

To check, run this small code on dev console

const k = [1, 2];
const l = k
k === l
> true
const m = [...k]
m
> [1, 2]
k === m
> false

With ES6+ you can simply do this

const original = [1, 2, 3];
const newArray = [...original];

With ES6+ you can simply do this

const original = [1, 2, 3];
const newArray = [...original];

The documentation for spread syntax is here

To check, run this small code on dev console

const k = [1, 2];
const l = k
k === l
> true
const m = [...k]
m
> [1, 2]
k === m
> false
Source Link
Arghya C
  • 10.1k
  • 4
  • 51
  • 70

With ES6+ you can simply do this

const original = [1, 2, 3];
const newArray = [...original];
lang-js

AltStyle によって変換されたページ (->オリジナル) /