How to add and item to array only if it doesnt exist already using javascript? -


this question has answer here:

i have array called myarray[]. how can add item myarray if item doesn't exist in array ?

  myarray.push({ url: urlvalue, filename: filenamevalue }); 

edited: tried following double pushed data after 3th push:

if (files === undefined || files.length == 0)         {             myarray.push({ url: urlvalue, filename: filenamevalue });          }      for(var g=0; g<myarray.length; g++){             if(myarray[g].url == urlvalue)             {               alert('already in array');             }             else             {                     myarray.push({ url: urlvalue, filename: filenamevalue });              }//end of else            }//end of loop 


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -