3 examples of 'check if value already exists in array javascript' in JavaScript

Every line of 'check if value already exists in array javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
81function valueExists(value: any) {
82 return value != null;
83}
3function addToArrayIfNotThere(value, array) {
4 var i;
5 for (i = 0; i < array.length; i++) {
6 if (array[i] === value) {
7 return i;
8 }
9 }
10 array[i] = value;
11 return i;
12}
346function isExistingAndAdd(search: string, array: string[]) {
347 if (array.indexOf(search) >= 0) {
348 array.push(search);
349 return true;
350 }
351 array.push(search);
352 return false;
353}

Related snippets