How to know if an object in the array?

var arr = [
{id: 1, name: '1'},
{id: 2, name: '2'},
{id: 3, name: '3'}
]

I need a function that will output true if in the array there is an object with the selected id
March 23rd 20 at 19:42
3 answers
March 23rd 20 at 19:44
Solution
(arr.find(item => item.id == {id}) && true) || false
March 23rd 20 at 19:46
Solution
var hasId = arr.some(o => o.id === 2);
instead of two insert desired value id
March 23rd 20 at 19:48
Solution
function isInArray(id, arr) {
 if (arr.some(e => e.id === id)) {
 return true;
}
 return false;
}

Find more questions by tags JavaScript