Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
28,199 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
216,083 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!