I have few arrays of JSON objects.I need to iterate over the arrays and return true if there are two or more elements with the same userId value.
[{
"name":"John",
"age":30,
"userId": 5,
}],
[{
"name":"Benjamin",
"age":17,
"userId": 5,
}],
[{
"name":"Johnatan",
"age":35,
"userId": 10,
}]
Here is my method so far, I'm iterating over the array and checking is there a user with 506 userId presence.
isPostedMultiple = (data) => {
for (let j = 0; j < data.length; j++) {
if (data[j].UserId == '506') {
console.log('506 data :', data[j]);
} else {
console.log('not 506 data');
}
}
}