Answers for "array check if value exists and push"

1

js push into array if item exist

if(this.items.indexOf(item) === -1) {
    this.items.push(item);
    console.log(this.items);
}
Posted by: Guest on June-13-2021
0

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

Code answers related to "array check if value exists and push"

Code answers related to "Javascript"

Browse Popular Code Answers by Language