Q:- What is JavaScript Arrays ?
Answer:- Collection of item’s can be called as Array and An Array can have collection of either Same or different items.
The Items can be a Number, String, Boolean, Object etc.
Eg:- const marks = [50,60,70,80,90]; { Array having same values }
const arr1 = [ 10, 20.00, "rozzer", false, null ]; { Array having Different values }
In JavaScript Array's are zero Indexed which means values start from the 0th position.
The Values of an array can be access using the index position
How to access array values
let marks = [75, 80, 85, 90, 95, 99]; console.log(marks[0]) --> output will be 75 console.log(marks[1]) --> output will be 80
Getting the length of array’s
let marks = [75, 80, 85, 90, 95, 99]; 0 1 2 3 4 5 --> { index } console.log(marks[0]) --> output will be 75 console.log(marks.length) --> output will be 6
Array’s Values can also be changed
let marks = [75, 80, 85, 90, 95, 99]; marks[1] = 92; so now the marks array becomes now console.log(marks); output will be [75, 92, 85, 90, 95, 99];
Arrays are Mutable, Means existing values of array can be changed.
The Type of an array is Object in JavaScript.
Example:- const number = [1, 2, 3, 4, 5, 6]; console.log(typeof number); will return the Output as Object