Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > Ajax and JavaScript

The JavaScript Pocket Guide: Arrays

  • Print
  • + Share This
Arrays and loops have endless uses in JavaScript programming. Lenny Burdette tells you all about arrays.
This chapter is from the book

This chapter is from the book

Arrays are a great tool for organizing and manipulating a lot of data. JavaScript arrays can store any of the JavaScript data types in any order. If you store your data in arrays, operating on it is simply a matter of looping over each value. It's a simple operation, but you'll find that arrays and loops have endless uses in JavaScript programming.

Creating Arrays

The best way to create a new array is with the array literal syntax ([]), but the array constructor function is available too. If you pass a single number value to the constructor function, you get an array filled with that many undefined values.

var myArray = [];
var myFilledArray = new Array(4);
myFilledArray;
[undefined, undefined, undefined, undefined]
  • + Share This
  • 🔖 Save To Your Account