I have a basic problem with Javascript. This code is below.
var users = [{"user":{"id":1,"username":"google"}},{"user":{"id":2,"username":"yahoo"}}]
const result = users.filter(users.id === 1);
console.log(result);
I want to get result if user_id exist in array or not.
The error is:
false is not a function
You need to take a callback, like an arrow function, with the right properties to the id, because you have a nested structure for every user.
var users = [{ user: { id: 1, username: "google" } }, { user: { id:2, username: "yahoo" } }];
const result = users.filter(user => user.user.id === 1);
console.log(result);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With