Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript check if value exists in array of objects

var arr = [{ id: 1, name: 'JOHN' }, 
  { id: 2, name: 'JENNIE'}, 
  { id: 3, name: 'JENNAH' }];

function userExists(name) {
  return arr.some(function(el) {
    return el.name === name;
  }); 
}

console.log(userExists('JOHN')); // true
console.log(userExists('JUMBO')); // false
Comment

how to check if an element exists in an array of objects js

var arr = [{ id: 1, username: 'fred' }, 
  { id: 2, username: 'bill'}, 
  { id: 3, username: 'ted' }];

function userExists(username) {
  return arr.some(function(el) {
    return el.username === username;
  }); 
}

console.log(userExists('fred')); // true
console.log(userExists('bred')); // false
Comment

how to check if object exists in array javascript

function containsObject(obj, list) {
    var i;
    for (i = 0; i < list.length; i++) {
        if (list[i] === obj) {
            return true;
        }
    }

    return false;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: array shift javascript 
Javascript :: how to check password and confirm passwor in joi 
Javascript :: bind an event to dom element angular 
Javascript :: select field in react native 
Javascript :: deduplicate array javascript 
Javascript :: duplicate elements of array multiple times 
Javascript :: javascript file on select 
Javascript :: useeffect react example 
Javascript :: how to delete duplicate elements in an array in javascript 
Javascript :: remove undefined element from array 
Javascript :: inheritance in javascript 
Javascript :: create an element jquery 
Javascript :: js increment and decrement function for cart 
Javascript :: adding background video angular 6 
Javascript :: javascript get nested element 
Javascript :: mysql json_array_append 
Javascript :: array iteration 
Javascript :: javascript get string from array with space between 
Javascript :: sum values in array javascript 
Javascript :: check type of variable in javascript 
Javascript :: Conflicting peer dependency: react@18.0.0 npm WARN node_modules/react 
Javascript :: how to convert string to sentence case in javascript 
Javascript :: merge-sort js 
Javascript :: how to make a string with unique characters js 
Javascript :: javascript emit event 
Javascript :: jquery cget lineheight in pixels 
Javascript :: moment js get french time 20:00:00 
Javascript :: callback hell javascript 
Javascript :: how to reverse a string in JavaScript using reduce function 
Javascript :: how to convert an object to a list in js 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =