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

128
Visualizações
JS push arrays to main array with key name

I have solidIcons which contains:

['book', 'apple', 'smile', 'pencil']

and regularIcons:

['flower', 'clock', 'house', 'bird']

I want to create the following array from the two:

{ 
  'solid-icons': ['book', 'apple', 'smile', 'pencil'], 
  'regular-icons': ['flower', 'clock', 'house', 'bird'], 
}

The goal is to be able to use map to loop through either solid-icons or regular-icons.

I'm trying:

let allIcons = [];

allIcons["solid-icons"] = solidIcons;
allIcons["regular-icons"] = regularIcons;

This is creating

0: [solid-icons: Array()] 
1: [regular-icons: Array()] 

The issue is that O cannot simply access an array group with allIcons["solid-icons"] I have to use the index allIcons[0]. How can i create the array in such a way that i can use the solid-icons or regular-icons to access without the index.

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

0

I think you can just use object literal:

let allIcons = { 
  'solid-icons': ['book', 'apple', 'smile', 'pencil'], 
  'regular-icons': ['flower', 'clock', 'house', 'bird'], 
}

You are not creating an array but object.

about 4 years ago · Juan Pablo Isaza Relatório

0

let allIcons = [] - this is array, you need let allIcons = {} instead

let allIcons = {};

allIcons["solid-icons"] = solidIcons;
allIcons["regular-icons"] = regularIcons;
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