javascript - change object if exists -
i'm filling array objects. want check if object id
exists.
if object exists replace value
in object.
for example:
function art(id,value) { this.id=id; this.value=value; }
an array var my_array=[];
adding array my_array.push(art);
how check if object exists , replace new value.
you should use key pair type associative array don't need check exists because:
- if doesnt exist created.
- if exist overwritten.
example:
var my_array = new array(); function art(id,value) { this.id=id; this.value=value; } var myart = new art(1,'value'); //if array item id exists overidden else new //array item created my_array[myart.id] = myart;
updated clarity
Comments
Post a Comment