Answers for "array check if value exists"

PHP
22

check if array has value php

$myArr = [38, 18, 10, 7, "15"];

echo in_array(10, $myArr); // TRUE
echo in_array(19, $myArr); // TRUE

// Without strict check
echo in_array("18", $myArr); // TRUE
// With strict check
echo in_array("18", $myArr, true); // FALSE
Posted by: Guest on January-21-2020
5

javascript method to see if item exists in array

var fruits = ["Apple", "Banana", "Mango", "Orange", "Papaya"];
    
    // Check if a value exists in the fruits array
    if(fruits.indexOf("Mango") !== -1){
        alert("Value exists!")
    } else{
        alert("Value does not exists!")
    }
Posted by: Guest on April-16-2020
6

check value exist in array javascript

[1, 2, 3].includes(2);     // true
[1, 2, 3].includes(4);     // false
[1, 2, 3].includes(1, 2);  // false (second parameter is the index position in this array at which to begin searching)
Posted by: Guest on June-27-2020
1

check if a element exists in array javascript

const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.includes("Mango")   // Returns true
Posted by: Guest on August-04-2021
1

how to check if an element already exists in an array in javascript

function includes(arrayOfArrays, item) {
    let array, i, j;
    for(i=0; i<arrayOfArrays.length; ++i) {
        array = arrayOfArrays[i];
        for(j=0; j<array.length; ++j) {
            if(array[j] === item) {
                return true;
            }
        }
    }
    return false;
}
Posted by: Guest on June-06-2021
-2

Checking whether a value exists in an array javascript

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

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

checkAvailability(fruits, 'kela');   // false
checkAvailability(fruits, 'banana'); // true
Posted by: Guest on December-08-2020

Code answers related to "array check if value exists"

Browse Popular Code Answers by Language