In JavaScript, an array is a type of object that is used to store a collection of values, such as numbers, strings, or even other objects. Arrays are a fundamental data structure in JavaScript, and they provide a convenient way to work with groups of related data.
Sample Code
Output
Why Use Arrays ?
If you have a list of items (a list of names, for example), storing the names in single variables could look like this.
An array can hold many values under a single name, and you can access the values by referring to an index number.
You can also create an array, and then provide the elements.
Example
Using the JavaScript Keyword new
The following example also creates an Array, and assigns values to it.
Sample Code
Output
Accessing Array Elements
You access an array element by referring to the index number.
Sample Code
Output
Changing an Array Element
This statement changes the value of the first element in name.
Sample Code
Output
The length Property
The length property of an array returns the length of an array (the number of array elements).
Sample Code
Output
Adding Array Elements
The easiest way to add a new element to an array is using the push() method.
Related Searches to JavaScript Arrays with Examples
javascript arrays javascript array javascript arrays with examples what are javascript arrays what are the 3 types of arrays what is array types in javascript what is array in javascript with example array how to create an array in javascript how to declare an array in javascript javascript array methods with examples array in javascript example types of array in javascript javascript list how to access array of objects in javascript types of array in javascript with example array methods in javascript