![]() CATEGORIES: BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism |
Number Object Properties
Number Object Methods
Objects as associative arrays Associative arrays are arrays that use strings in place of index numbers, for key elements.Using an associative array is quite similar to using a property name with a regular object; you just do it in an array format. Syntax: var array_name = new Array(); array_name['key1'] = value1; array_name['key2'] = value2; // ... - "array_name" is the name of the array. array_name['key'] = value; • Accessing an associative array is the same as a normal array, except that you use an index string rather than an index number (array_name['key']). <script type="text/javascript"><!-- var arrex = new Array(); arrex['site'] = 'http://coursesweb.net'; arrex['course'] = 'Web programming'; arrex['tutorials'] = 'JavaScript';
alert(arrex['site']); // http://coursesweb.net --></script> Numerically indexed arrays. An Array is an enumerated list of variables. It's a programming construct that allows programmers to replace this… x0=0; x1=1; x2=2; x3=3; x4=4; x5=5; …with this… x[0]=0; x[1]=1; x[2]=2; x[3]=3; x[4]=4; x[5]=5; The index (the number in the brackets [] )can be referenced by a variable, allowing for easy looping through the data structure. for(i=0; i<6; i++) { document.writeln(x[i]+'<br>); } Which will output the following… Creating A New Array. var myArray = new Array(10); If you want to create a new Array simply use brackets [] like this… var myArray = []; For instance. var badArray = new Array(10); // Creates an empty Array that's sized for 10 elements. var goodArray= [10]; // Creates an Array with 10 as the first element. . If you had wanted to add more than one item then badArray would be initialized correctly since Javascript would then be smart enough to know that you were initializing the array instead of stating how many elements you wanted to add.. 46.Arrays: Methods Description An Array is used to store a number of values (called as elements) in order with a single variable.Can be created using javascript array object constructor. Parameters size : The length of the array. The maximum length allowed for an array is 4,294,967,295. Date: 2016-01-03; view: 1078
|