John Stimac
John Stimac

Reputation: 5493

Javascript Array Issue

ok, so when i do array=array2 then change something in array2 it changes array. how do i prevent this?

Upvotes: -1

Views: 85

Answers (2)

meder omuraliev
meder omuraliev

Reputation: 186562

Do..

b = a.slice()

Why? Because assignment would just reference the origin object. slice or concat would create a new object.

Upvotes: 1

glebm
glebm

Reputation: 21090

var b = a.concat();

Upvotes: 0

Related Questions