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

152
Visualizações
JS get key name using map()

I have the following object:

{
    "thumbnail": {
        "height": 150,
        "width": 150,
    },
    "medium": {
        "height": 165,
        "width": 300,
    },
    "large": {
        "height": 352,
        "width": 640,
    }       
}

I want to create the following array from the object.

[
    {
        "slug": "thumbnail",
        "name": "Thumbnail"
    },
    {
        "slug": "medium",
        "name": "Medium"
    },
    {
        "slug": "large",
        "name": "Large"
    },
    {
        "slug": "full",
        "name": "Full"
    }
]

How can I get the object key name to add to the array? I tried the following:

map( imageSizesArray,
   ( { key } ) => ( { value: key, label: key.toUpperCase() } )
);

but it does not work

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

0

const obj = {
    "thumbnail": {
        "height": 150,
        "width": 150,
    },
    "medium": {
        "height": 165,
        "width": 300,
    },
    "large": {
        "height": 352,
        "width": 640,
    }       
}

const retrnArr = Object.keys(obj).map(e =>{
return  { 'value': e , 'label' : e.toUpperCase()}
});
console.log(retrnArr)

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