O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Arrays

  var x = y = 5;   var z = 10;   var results = "x + y + z = " + (x+y+z);   var s1 = "jQuery";   var s2 = "JavaScript"   var s3 = s1 + " & " + s2;

You can create arrays in a few different ways. You can create them in the definition using [] brackets, such as var arr=[1,2,3]. You can also create a new array object and add items to it using the push() method. You can access items in the array using the arr[index] method. The following code snippet shows an example of creating an array in each of these ways.

<script>   var weekdays = ["Mon", "Tue", "Wed", "thur", "Fri"];   var weekend = new Array();   weekend.push("Sat");   weekend.push("Sun");   document.write(weekdays.toString() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required