Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

91
Visualizações
Sorting of Object inside Object On the basis of Order key

Sorting & arrange list of object inside object on the basis of order key

const listing = {
   "football":{
      "name":"FOOTBALL",
      "slug":"football",
      "arr":[],
      "order": 4
   },
   "table-tennis":{
      "name":"TABLE TENNIS",
      "slug":"table-tennis",
      "arr":[],
      "order": 1
   },
   "cricket":{
      "name":"CRICKET",
      "slug":"cricket",
      "arr":[],
      "order": 5
   },
   "badminton":{
      "name":"BADMINTON",
      "slug":"badminton",
      "arr":[],
      "order": 2
   },
   "hockey":{
      "name":"HOCKEY",
      "slug":"hockey",
      "arr":[],
      "order": 3
   }
}
Object.keys(listing).sort().map((item) => {
  return (
    <div>
      <div onClick={() => sportsKitFilter()}>{listing[item].name}</div>
    </div>
  )
})

Actual Result:-

BADMINTON
CRICKET
FOOTBALL
HOCKEY
TABLE TENNIS

Expected Result:-

TABLE TENNIS
BADMINTON
HOCKEY
FOOTBALL
CRICKET

So, In the expected result, Storing is on the basis of order key

Guide me, In this scenerio??

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Currently i am sorting listing.order. try this code it's working !

 Object.keys(listing).sort((a, b) => listing[a].order - listing[b].order).map((item) => {
      return (
        <div>
          <div onClick={() => sportsKitFilter()}>{listing[item].name}</div>
        </div>
      )
    })
about 4 years ago · Juan Pablo Isaza Relatório

0

How's this for you?

const listing = {
  football: {
    name: "FOOTBALL",
    slug: "football",
    arr: [],
    order: 4,
  },
  "table-tennis": {
    name: "TABLE TENNIS",
    slug: "table-tennis",
    arr: [],
    order: 1,
  },
  cricket: {
    name: "CRICKET",
    slug: "cricket",
    arr: [],
    order: 5,
  },
  badminton: {
    name: "BADMINTON",
    slug: "badminton",
    arr: [],
    order: 2,
  },
  hockey: {
    name: "HOCKEY",
    slug: "hockey",
    arr: [],
    order: 3,
  },
};

const ordered = Object.keys(listing).sort(
  (a, b) => listing[a].order - listing[b].order
).map(item => ["YOUR JSX HERE"]);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda