Sort followed by map not working on React

0

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

{this.mapasVetados
    .sort((a,b) => {
        return a.ordem - b.ordem
    })
    .map(mapa => {
        if (mapa.vetado) {
            return (<Vetados
                         mapa = {mapa.nome}
                         ordem = {mapa.ordem}
                    />)
        }
    })
}
    
asked by anonymous 28.11.2018 / 14:46

1 answer

0

I was able to solve the problem!

Not all objects being ordered had the order property, hence the sort "bugava" and did not change the array. By adding a value (0) at all, it worked

    
28.11.2018 / 17:48