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

object exists in array javascript

array.findIndex((obj) => obj.id === obj.id) !== -1
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 :: mdn object assign 
Javascript :: react-data-table-component cell action 
Javascript :: jquery bootstrap checkbox val 
Javascript :: npm react-syntax-highlighter 
Javascript :: prettier printWidth 
Javascript :: how to deploy firebase angular 10 
Javascript :: enzyme testing 
Javascript :: flatten nested object 
Javascript :: usestate in react js 
Javascript :: how to get MathJax 
Javascript :: get url from string javascript 
Javascript :: console.log(...) is not a function 
Javascript :: javascript inheritence 
Javascript :: ternaire javascript 
Javascript :: Children in JSX 
Javascript :: look through object keys javascript 
Javascript :: range number in js 
Javascript :: express cookieparser 
Javascript :: copia independiente array javascript 
Javascript :: round number javascript 
Javascript :: add svg in react 
Javascript :: bin to bit string javascript 
Javascript :: javascript name convention 
Javascript :: js get path from url 
Javascript :: how to slice array in angular 6 
Javascript :: navigation prompt javascript 
Javascript :: js array clear 
Javascript :: how to validate password and confirm password on react form hook 
Javascript :: hooks developed by react native 
Javascript :: how to seperate header body and footer in node 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =