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() ...

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.