Javascript array The Array is used to store multiple values in a single variable. What is an Array? An array is a special variable, which can hold more than one value, at a time. If you have a list of items (a list of car names, for example), storing the cars in single variables look like this: cars1=" Honda "; cars2=" Suzuki "; cars3=" BMW "; Create an Array An array can be defined in three ways. The following code creates an Array object called myCars: 1. var myCars=new Array(); // regular array(add an optional integer // argument to control array’s size) myCars[0]=”Honda”; myCars[1]=”Suzuki”; myCars[2]=”BMW”; 2. var myCars=new Array(“Honda”,”Suzuki”,”BMW”); // condensed array 3. var myCars=[“Honda”,”Suzuki”,”BMW”]; // literal array Demonstrate the use of array in javascript <!DOCTYPE HTML> <html> <head> <title> JavaScript Language </title> <script type=" text / ja...
Comments
Post a Comment