here's the code:
data = [
{
'id': 'asdja',
'username': 'james',
},
{
'id': 'asqweja',
'username': 'rhou',
},
{
'id': 'asdqweqj',
'username': 'arianne'
},
{
'id': 'qpoaksl',
'username': 'ryan'
}
];
I'm trying to check if username already exists.
For example if I input "james" then it should display "Username already exists"
I try to used find:
if (username === data.find((x: any) => x.username === x.username) {
console.log('Username already exists');
} else {
console.log('');
}
if (data.find((x: any) => x.username === x.username). when you compare object, NOT compare that has the same properties, e.g.obj={a:10}; obj1={a:10}; bool equals=obj===obj2;equals is FALSE