1
My API is returning a array
with the objects in the following structure:
[
{id: 1, name: "Flávio", position: "SP - Atacante"},
{id: 2, name: "João", position: "SP - Goleiro"},
{id: 3, name: "Fernando", position: "RJ - Zagueiro"},
{id: 5, name: "Robert", position: "SP - Todas"},
];
I need to take this guy’s last position (object with position: 'SP - Todas'
) and remove SP text - leaving only "All".
I tried it this way and it worked (should not be the best way, if you have suggestions, thank you).
jogadores.map((jogador, i) => {
if (jogador.position.includes('Todas')) {
console.log(jogador.position.substr(4));
};
});
The problem is that I need to return the array with this last edited object, but I’m not sure how to do it.
You want to remove the
SP
in the "last position" or in the one that has the text "All"? in the example is the same, but it is always the same?– Sergio