Here is the snippet of code:
data = [
{
'id': 'asdjxv',
'username': 'emma',
},
{
'id': 'asqweja',
'username': 'adam',
},
{
'id': 'asdqweqj',
'username': 'janet'
}
];
I am attempting to verify if the username
already exists.
For instance, if I input "adam"
, then it should show "Username already exists"
I have attempted using the find method:
if (username === data.find((x: any) => x.username === x.username) {
console.log('Username already exists');
} else {
console.log('');
}