60 likes | 249 Views
Arrays. JavaScript 10. Arrays. Arrays contain a set of data represented by a single variable name Its like a collection of variables contained in one variable Arrays usually store a group or list of related information To create an array you need Array_name = new Array(number of elements);
E N D
Arrays JavaScript 10
Arrays • Arrays contain a set of data represented by a single variable name • Its like a collection of variables contained in one variable • Arrays usually store a group or list of related information • To create an array you need • Array_name = new Array(number of elements); • Array must be capitalized, and the values can be of different data types
Arrays • The numbering of elements start with the number 0 • To assign values to the array elements is similar to assigning a variable a value • Students = new Array (16); • Students[0] = “Kyle”; • Students[1] = “Blia”; • The array has 16 values, to call any of the values, use the name (Students) and the element [1]
Change the Array Values • It is possible to change the array value at any time just like a variable • Students[1] = “Jake”; • It is also possible to add on to an array • An example, the array has 5 elements, a sixth element can be added by using the array name (Students) the element [5] follow by the value(“Lisa”);
The Array’s Property • The array object also has one property • The length property is used to display the number of elements in the array • document.writeln(Students.length) will display the number of element in the Student Array • An example of what you can do with an array is here
JavaScript 10 Assignment • Create Four different Arrays with at least 6 elements (start with 0) • Display some of the different elements in sentences • Create a function or several functions that will use all four arrays however you desire