Reputation:
How to remove a key from an object
This function takes an array of user objects and deletes the moto key-value pair on each user object.
I have tried this code:
function deleteAllMoto(users) {
for(var i=0; i<=users.length; i++) {
delete users[i].password;
return users[i];
}
Upvotes: 0
Views: 35
Reputation: 441
Something like this:
function deleteAllMoto (arr) {
arr.forEach(function(item) {
delete item.moto
})
return arr
}
From your code you are deleting password not moto, then trying to return each user instead of the whole array after the mutations.
Upvotes: 1
Reputation: 1571
deleteAllMoto
function should be
function deleteAllMoto(users) {
for(var i=0; i<=users.length; i++) {
delete users[i].moto;
}
return users;
}
Upvotes: 0