I have an array that looks like this:
var participants = [
{username: "john", time: null},
{username: "samira", time: null},
{username: "mike", time: null},
{username: "son", time:null}
]
To remove an item based on the username, I can do the following:
const index = participants.map(x => {
x.map(y => {
return y.username;
})
}).indexOf(username); //get index of username
participants.splice(index, 1);
After removing the item, if the index of the username returns "-1", does that mean the participants array becomes empty?
The expected output after removing the item with username 'son' would be:
[
{username: "john", time: null},
{username: "samira", time: null},
{username: "mike", time: null}
]
UPDATE:
It turns out that my array is nested within another array, as shown in the image below: