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 :: jquery clear click event 
Javascript :: add set time out in jquery 
Javascript :: javascript get form data 
Javascript :: react get input value on button click functional component 
Javascript :: reversing an array in js 
Javascript :: communication with service worker 
Javascript :: LazyLoad for images, Videos and Iframes JavaScript and JQuery 
Javascript :: get ckeditor textarea value in jquery 
Javascript :: loopback find or create 
Javascript :: scroll to top in react 
Javascript :: get input in terminal nodejs 
Javascript :: nextauth dynamic redirect after login 
Javascript :: react absolute path 
Javascript :: @editorjs/list window not defined 
Javascript :: get time from a date time in jquery 
Javascript :: how to set content length of an mp3 stream in nodejs 
Javascript :: How to more than one slot in graph node in godot 
Javascript :: string to accept two characters after point javascript 
Javascript :: jquery check if element has child 
Javascript :: logbox ignore warnings 
Javascript :: javascript time ago function 
Javascript :: nextjs check path in page 
Javascript :: trigger key jquery 
Javascript :: opal find element 
Javascript :: python phantomjs current url 
Javascript :: how to add an element to the last position of an array in javascript 
Javascript :: join last element of array javascript with different value 
Javascript :: float js precision 
Javascript :: run forset 
Javascript :: render image url in react native 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =