FAQ: Arrays - Create an Array

This community-built FAQ covers the “Create an Array” exercise from the lesson “Arrays”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise Create an Array

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I’ve copied the text exactly as it is from the example, but I still get error messages.

If you could please copy and past your code here I could help you try to figure this out.

Just a quick question: why is there an option to declare an array without assigning it to a variable. When would we need to do that, if at all? See code below which compiles without error:

[‘pool’, ‘drawing’, ‘cricket’];

Isn’t it just wasting memory?

I am in lesson3/12 in arrays (Java Script Syntax 2).
In the counting of index positions in the ‘Hello World’ code, the 6th position was the W. Does that mean that the ’ ’ are also counted and that ’ got the 0 position? Otherwise was it the empyy space between the words that got the 5th position?

0 1 2 3 4 5 6
H e l l o W o

const hello = ‘Hello World’;
console.log(hello[6]);
// Output: W

Thanks!

In lesson 2/12, we are asked to create an array based on the variable hobbies, like so:

const hobbies = ["Football", "Tennis", "Wine"];
console.log(hobbies); // prints [ 'Football', 'Tennis', 'Wine' ]

Why does it print single quotation marks to the array even though I used doubles?

You will find this to be the case when the system compiles your literals. It is not an issue, though. It has to do with the string literals being primitives that need to be given an object wrapper by the interpreter. It always uses single quotes in this step.

 console.log(typeof "Football")    //  'string'
2 Likes

Thanks for the quick response and for supplying an understandable explanation as always. Since the lesson gave me a pass on the original code I figured it was not an issue, but I wanted to ask out of curiosity.

I also tried putting the array elements in single quotes:

const hobbies = ['Football', 'Tennis', "Wine'];

which also prints in single quotes.

console.log(hobbies); // prints [ 'Football', 'Tennis', 'Wine' ]
1 Like

hi, i have set ny array but it still prints to the console with the square barackets i.e [‘jesus’,‘car’,‘9’]…is this still okay and how can i avoid those brackets being printed in the console

If we log an array, the actual object is printed to the display, including the brackets and quotes on strings. To log just the values we need to iterate the array. This will be covered once you get to the unit on loops.

1 Like