I am working with an array containing user objects, each of which has a latitude property. How can I filter this array to create a new array only containing users with the same latitude?
Here is what my initial array looks like:
let arrayToFilter = [
{
"user1" : {
"profile" : {
"name" : "user1",
"age" : "35",
"gender" : "male",
"latitude" : 57.267801888216965,
"longitude" : 16.451598081831214
}
},
"user2" : {
"profile" : {
"name" : "user2",
"age" : "50",
"gender" : "male",
"latitude" : 37.785834,
"longitude" : -122.406417
}
},
"user3" : {
"profile" : {
"name" : "user3",
"age" : "23",
"latitude" : 37.785834,
"longitude" : -122.406417
}
}
}
]
I attempted the following code snippet, but it does not seem to be effective...
let arr = arrayToFilter.filter(child => child.latitude === child.latitude)