JavaScript Arrays
JavaScript Arrays – Arrays are used to store multiple elements in a single variable. Elements in an array are assumed to represent members belonging to a type.
For example, prime numbers, names of students in a class, items to be displayed under a category, etc.
The syntax to initialize an Array in JavaScript is
var arrayName = [ element1, element2, .. elementN ]
where arrayName
is the name given to the array and would be referenced by this name in the script.
During initialization, the elements are enclosed in opening and closing square brackets, where the elements are separated by comma character.
To access an element of an array, you may use index [0:N-1] with arrayName
as shown in the following.
arrayName[index]
Arrays Tutorials
In the following tutorial, we cover different topics of Arrays covering CRUD operations, sorting, etc.
- JavaScript – Create Array
- JavaScript – Array Length
- JavaScript – Access Elements of Array using Index
- JavaScript – Loop over an Array
- JavaScript – Array forEach()
- JavaScript – Join Elements of Array
- JavaScript – Add Element to Starting of Array
- JavaScript – Add Element to End of Array
- JavaScript – Remove First Element of Array
- JavaScript – Remove Last Element of Array
- JavaScript – Remove Element at Specified Index
- JavaScript – Concatenate Arrays
- JavaScript – Sort a Numeric Array
- JavaScript – Sort a String Array
- JavaScript – Slice an Array
- JavaScript – Reverse an Array
- JavaScript – Find Index of Element in Array
- JavaScript – Filter Array
Arrays based on Datatype
Conclusion
In this JavaScript Tutorial, we have learnt about JavaScript Arrays, how they are initialized etc. In our next tutorial – JavaScript – Array Methods, we shall learn about different methods that an Array have.