Check if value exists in the array (AngularJS) [duplicate]

You could use indexOf function.

if(list.indexOf(createItem.artNr) !== -1) {
  $scope.message="artNr already exists!";
}

More about indexOf:

  • http://www.w3schools.com/jsref/jsref_indexof_array.asp
  • https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf

Leave a Comment