Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!