0

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.

2
  • allIcons["solid-icons"] = solidIcons Commented Feb 9, 2022 at 9:50
  • 2
    "I want to create the following array from the two:" That's not an array, that's an object. Commented Feb 9, 2022 at 9:51

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

let allIcons = {};

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.