Sort followed by map not working in React

Asked

Viewed 52 times

0

I have an array of objects and am trying to iterate with the map in that array after the method of sort, but it is iterating in the normal array, disregarding the method sort and the reordering.

{this.mapasVetados
    .sort((a,b) => {
        return a.ordem - b.ordem
    })
    .map(mapa => {
        if (mapa.vetado) {
            return (<Vetados
                         mapa = {mapa.nome}
                         ordem = {mapa.ordem}
                    />)
        }
    })
}

1 answer

0

I managed to solve the problem!

Not all objects being ordered had the order property, hence the "bugava" Sort and did not change the array. Adding a value (0) to all worked

Browser other questions tagged

You are not signed in. Login or sign up in order to post.