An array in JavaScript can store multiple values of different data types in a single variable. Arrays are dynamic, meaning their size can increase or decrease during runtime. To create an array, use the array literal syntax like var fruits = ["apple", "orange", "mango"] or the Array constructor like var fruits = new Array("apple", "orange", "mango"). Individual elements can be accessed by their index number. The length property returns the number of elements in the array. A for loop is commonly used to iterate through the elements of an array.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
43 views
Introduction To Arrays in JavaScript
An array in JavaScript can store multiple values of different data types in a single variable. Arrays are dynamic, meaning their size can increase or decrease during runtime. To create an array, use the array literal syntax like var fruits = ["apple", "orange", "mango"] or the Array constructor like var fruits = new Array("apple", "orange", "mango"). Individual elements can be accessed by their index number. The length property returns the number of elements in the array. A for loop is commonly used to iterate through the elements of an array.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
Introduction to Arrays in JavaScript
November 1, 2018 Tanmay Sakpal 0 Comments arrays in javascript, javascript arrays
JavaScript arrays are used to store multiple values in a single variable. An array in JavaScript can hold different elements We can store Numbers, Strings and Boolean in a single array. Also arrays in JavaScript are dynamic in nature, which means its size can increase or decrease at run time.
Syntax – Use the following syntax to create an Array object −
1var fruits = [ "apple", "orange", "mango" ];
2var fruits = new Array( "apple", "orange", "mango" ); // another way but not prefered
Access the Elements of an Array –
You access an array element by referring to the index number. This statement accesses the value of the first element in cars:
1var cars = ["Saab", "Volvo", "BMW"];
2var name = cars[0];
Access the Full Array –
With JavaScript, the full array can be accessed by referring to the array name: