7

I have three arrays:

  • arr1=["14","16","1"] — where I am selecting
  • arr2=["14"] — where I am comparing my selection from arr1
  • arr3=[] — where I am pushing the value.

How will I be able to check if my selection does not exist in arr2?

For example I selected 14 from arr1, since it is already existing in arr2, the button will be disabled and should not be pushed in arr3.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
user2756589
  • 431
  • 2
  • 7
  • 18
  • [Search objects in Array](http://stackoverflow.com/questions/15610501/in-angular-i-need-to-search-objects-in-an-array) – AlvaroAV Nov 20 '13 at 10:02

1 Answers1

26

That is a JavaScript relating question, not AngularJS. But may that answer your question:

if(arr2.indexOf("14") == -1){
  arr3.push("14");
}
tschiela
  • 5,231
  • 4
  • 28
  • 35