I'm trying to .filter
my array object to find out if the ids
are equal or not to another object.
Initial JSON: --
var user =
{
"requests" : [
{
"name" : "Test1",
"id" : "590e6c94b2d6e52674992d16",
"email" : "kram@kram.com",
"user" : "test",
"accepted" : false
},
{
"name" : "Test2",
"id" : "590e6c8bb2d6e52674992d15",
"email" : "test@test.com",
"user" : "_test",
"accepted" : false
}
]
}
Compare initial JSON with this object: --
var acceptOrdeny = {
"name" : "Test1",
"id" : "590e6c94b2d6e52674992d16",
"email" : "kram@kram.com",
"user" : "test",
"accepted" : false
}
I'm using filter
and .equals()
comparator to find out if they are match or not. But I'm getting request.id.equals is not a function
error.
user.requests = user.requests.filter(request => !(request.id.equals(acceptOrdeny.id)));
Can anyone pointout what's wrong with this? surely .equals() does exist?
var user =
{
"requests" : [
{
"name" : "Test1",
"id" : "590e6c94b2d6e52674992d16",
"email" : "kram@kram.com",
"user" : "test",
"accepted" : false
},
{
"name" : "Test2",
"id" : "590e6c8bb2d6e52674992d15",
"email" : "test@test.com",
"user" : "_test",
"accepted" : false
}
]
}
var acceptOrdeny = {
"name" : "Test1",
"id" : "590e6c94b2d6e52674992d16",
"email" : "kram@kram.com",
"user" : "test",
"accepted" : false
}
user.requests = user.requests.filter(request => !(request.id.equals(acceptOrdeny.id)));
via MrNew
No comments:
Post a Comment