You see, I have a multidimensional array and I need to remove a field from said array but I can't.
I should clarify that I am using firebase's firestore.
That's my code:
db.collection("database").doc("users").get().then(data => {
var arrs = data.users;
var remove = [{ name: "Juan" }, { name: "Alex" }]; // Este valor lo obtengo dependiendo de los checkbox's seleccionados
var newArr = [];
for (var i = 0; i < arrs.length; i++) {
var index = arrs[i].indexOf(remove);
if (index !== -1) {
newArr.push(data.users.splice(i, 0));
}
}
db.doc("database/users").update({
users: newArr
});
});
This is the JSON that returns me when I list the users:
{
"users": [{
"name": "Juan"
"ave": 23
}, {
"name": "Alex",
"age": 17
}, {
"name": "Josefina",
"age": 18
}, {
"name": "Carla",
"age": 25
}]
}
What is supposed to return me when removing the indicated fields, would be this:
{
"users": [{
"name": "Josefina",
"age": 18
}, {
"name": "Carla",
"age": 25
}]
}
I need help, I've been trying to find a solution for more than 2 hours. Beforehand thank you very much
You can use
filter
to eliminate those indicated elements.More info .