Changing object value inserted in an array

Asked

Viewed 27 times

0

Take a look at this example: https://jsfiddle.net/b4w6jqgf/1/

In it I have two arrays:

__options e __defaultOptions;

When starting push __options by inserting the __defaultOptions object. Later I change the value of the object at position 0, setting in the field "maxsize" the value 1500.

It turns out that the value is also assigned in all other positions of the array.

I imagine you are just referencing the __defaultOptions object at the array positions, being the same object at all positions, so when I change the value at one of the positions, everyone has its value changed.

How can I get around this issue?

Is there any way to import data from an object itself, and not reference the object?

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.