

- Home
- JavaScript
- JavaScript Array
Overview -JAVASCRIPT ARRAY
JavaScript array is an object that store a collection of multiple values of different types under a single name.ย
Remember in JavaScript arrays are not primitive ( means of value type of datatype like integer, float, double or characters).
JavaScript Arrayย has following characteristics:
- JavaScript arrays are resizable and can contain a values of different data types.
- JavaScript arrays are zero-indexed: array elements are accessed using index value and the first element of the array is at index 0,ย the second is at 1 and so on, and the last element is at the total length of arrayย ย minus 1.
- JavaScript arrayย are not associative arrays, so element can not be accessed using strings as indexes (non negative integers)
Creating An Array
Array can be created in two ways:
- ย Using an array literal
const colors= ["red", "green"];
2. Using new keyword
const colors= new Array ("blue", "orange")
const colors = ['red', 'blue', 'yellow'];
// More examples
// empty array
const myArray = [ ];
// array of numbers
const numberArray = [ 10, 20,30, 40];
// array of strings
const stringArray = [ 'Kaushal', 'Kishan', 'Megha'];
// array with mixed data types
const mixData = ['India', 'USA', 1, true];
In JavaScript arrayย can also store objects, functions and arrays. for example
const myArray = [
{'name': 'kaushal'},
[1, 2 ,3],
function hello() { console.log('hello')}
];
Array length property
Theย length property returns the number of elements in an array and can also set the length of an array.ย array.length will return total number of element in an array andย array.length= 5 set the length of array to 5.ย
Accessing Array Elements
We can access array elements using indices 0,1,2 …
const myArray = ['h', 'e', 'l', 'l', 'o'];
// first element
console.log(myArray[0]); // "h"
// second element
console.log(myArray[1]); // "e"
For Detail video for array & JavaScript-
Recent Post
The New AI sensation Deepseek
- February 7, 2025
- 5 min read
Var keyword in C#
- May 8, 2024
- 4 min read
What is Cloud Computing ? Definition &
- April 2, 2024
- 4 min read