Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Two-Dimensional Arrays

Array literal

What is an "array literal," mentioned at 4:36 in the video?

2 Answers

alastair cooper
alastair cooper
30,617 Points

An array literal is an array that is declared in your code, as opposed to being created dynamically when your code runs.

ie I could declare var arr = ['value1' , 'value2' , 'value3']

This is an array literal.

You will see the same thing with objects


var obj = { name: 'myName' }

however, the statement ...

var obj = new OBJECT('myName')

creates the object in memory dynamically when the code is run, instead of me 'literally' declaring it in my code.

Hope this helps


Thanks Alastair!

Steven Parker
Steven Parker
227,167 Points

It's just an array that is contained in your code. Here's an example of assigning a variable using an array literal:

var myArray = [ "one", "two", "three" ];  // this array has 3 strings

Thanks Steven!