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:

  1. if doesnt exist created.
  2. 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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -