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
Also in JavaScript:
- jquery get all select options
- cypress fixture
- js entries
- detect if user is online react
- trigger click jquery
- vue js cdn
- how to get a channelid discord.js
- how to insert a value into an array javascript
- refresh data after some time angular
- react native scrollview
- jquery on body click
- empty array js
- javascript template string
- queue data structure in javascript 2018
- angular 6 key value pair getvalue example
- ignore node_modules
- operator to return specific data of a mongodb query
- cookie clicker hack
- convert camelcase to sentence case javascript
- on click fade out jquery
- button style in jquery datatable
- javascript element by class
- beautify json python
- javascript format date yyyy-mm-dd