Clicking an object reference to an array

As far as I can see in this situation:

var x = [];
var y = {};

y.someProp='asd';

This does not work:

x.push(y);

What I want to do is add the link y to x so that later, if I "delete y;" I want it to be removed from the x array as well.

+3
source share
4 answers

You mix variables, references, and objects.

Execution delete y;deletes the variable y. Since the variable no longer exists, it naturally will no longer matter. Thus, the link contained in the variable is missing.

, , , . , .

. , , . , , .

+2

delete. , , . - " " , - JavaScript.

0

?

Var x=[{}]; var y=x[0];

: , . : "" ? delete array.splice(), , ?

-, y , , , , , . , -

var x=[]; var y={}; y.arrayIndex=(x.push(y)-1);

// later on, you want to get rid of y

delete x[y.arrayIndex]; delete y;
0

:  

x.push(y);

, , , - y .

delete , , , , .

var y = {"someprop":true};

delete y;
alert(y.someprop); // alerts "true"

, enter:

javascript:var y = {"someprop":true}; delete y; alert(y.someprop);
0

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


All Articles