I try like this :
<script type="text/javascript">
var clubs = [
{id: 1, name : 'chelsea'},
{id: 2, name : 'city'},
{id: 3, name : 'liverpool'},
{id: 4, name : 'manchester united'},
{id: 5, name : 'arsenal'}
];
var selectedId = 3;
if(clubs.includes(selectedId))
console.log('The selected id exist');
else
console.log('The selected id does not exist');
</script>
But it does not works. I only works if clubs array is array one dimensional
How can I solve it?
I want to do it with one statement. No loop
some()method as suggested in your previous question a few minutes ago.clubs.some(o => o.id == selectedId)3in yourclubsarray. There's a{id: 3, name: 'liverpool'}object though.3in your array. Javascript doesn't know that it should map3toidunless you tell it to do so as suggested by @Mohammed-Usman