check if array does not contain value javascript
snippet in javascript

check if array does not contain value javascript

user704

var fruits = ["Banana", "Orange", "Apple", "Mango"];

var n = fruits.includes("Mango"); // true

var n = fruits.includes("Django"); // false

check if elemnt is present in arry or not

user5157


var fruits = ["Banana", "Orange", "Apple", "Mango"];

var n = fruits.includes("Mango");
 

Checking whether a value exists in an array javascript

user1682

const fruits = ['apple', 'banana', 'mango', 'guava'];

function checkAvailability(arr, val) {
  return arr.some(arrVal => val === arrVal);
}

checkAvailability(fruits, 'kela');   // false
checkAvailability(fruits, 'banana'); // true

check if an element is already in an array

user5439

private boolean ZitAlInArray(int value, List<Integer> list) {
  return array.indexOf(value) > -1;
}

private boolean zitAlInArray(int[] array, int index) {
		for (int i = 0; i < index; i++) {
			if (array[i] == array[index]) {
				return true;
			}
		} 
		return false;
	}

how to Check if an array contains a string

user3107

// To check if an array contains a string 

const colors = ['red', 'green', 'blue'];
const result = colors.includes('red');

console.log(result); // true

// Or 

const colors = ['Red', 'GREEN', 'Blue'];
const result = colors.map(e => e.toLocaleLowerCase())
                     .includes('green');                          

console.log(result); // true