$ .map jquery acting as a pointer

I did not find a name for the qualification, but that’s what I don’t understand.

let's say we create an array using $ .map

var categoriesTemp = ['a','b','c']
var tempData = $.map(categoriesTemp,function(el,i){
            return 0;
        });

After that, I assign a temporary table to two variables

var vector1 = tempData;
var vector2 = tempData;

What I don't understand is that when I change the value in vector1, it affects vector2 and vice versa, for example:

vector1[1] = 1;

Two variables will have values:

Vector1 = [0, 1, 0]
Vector2 = [0, 1, 0]

I read the jquery documentation on $ .map but didn't find a hint. Can someone explain how this happens?

+4
source share
1 answer

jQuery $.map. , - Javascript. $.map (- ), , . ( ):

var tempData = [1,2,3];

var vector1 = tempData;
var vector2 = tempData;

vector1 vector2.

+3

Source: https://habr.com/ru/post/1614061/


All Articles