The JavaScript Array reference provides a complete overview of array properties and methods used to store, access, search, transform, sort, and manage collections of data. Arrays are a core data structure in JavaScript and are used in almost every application.
What Is a JavaScript Array?
An array is an ordered list of values stored in a single variable.
Each value is called an element, and each element has an index starting from 0.
Explanation:
Stores multiple related values in one variable.
Array Properties
length
Returns the total number of elements in the array.
Explanation:
Returns 3 for three elements.
Creating Arrays
Explanation:
Creates an array with numeric values.
Accessing and Updating Elements
Explanation:
Accesses and updates elements using index positions.
Common Array Methods (Reference)
Add / Remove
-
push()→ add to end -
pop()→ remove from end -
shift()→ remove from start -
unshift()→ add to start
Search
-
includes()→ check if value exists -
indexOf()→ find index -
lastIndexOf()→ find last index -
find()→ find element by condition -
findIndex()→ find index by condition
Iteration / Transformation
-
forEach()→ loop through elements -
map()→ create new array -
filter()→ filter elements -
reduce()→ combine values -
some()→ check any match -
every()→ check all match
Sorting / Reordering
-
sort()→ sort elements -
reverse()→ reverse array
Extract / Combine
-
slice()→ extract portion -
splice()→ add/remove elements -
concat()→ merge arrays
Mutating vs Non-Mutating Methods
Some methods change the original array, others return a new array.
Mutating Methods:
push(), pop(), shift(), unshift(), sort(), splice(), reverse()
Non-Mutating Methods:
map(), filter(), slice(), concat(), includes()
Common Mistakes with Arrays
-
Forgetting that indexes start from
0 -
Mutating arrays unintentionally
-
Using
map()when no new array is required -
Confusing
slice()withsplice()
Summary of JavaScript Array Reference
| Category | Methods / Properties |
|---|---|
| Property | length |
| Add/Remove | push(), pop(), shift(), unshift() |
| Search | includes(), indexOf(), find() |
| Iteration | forEach(), map(), filter(), reduce() |
| Sorting | sort(), reverse() |
| Extract/Merge | slice(), splice(), concat() |
Conclusion
The JavaScript Array reference provides essential methods and properties to manage collections of data effectively. By understanding how to create arrays, access elements, and use built-in methods for searching, iterating, sorting, and transforming data, array handling becomes simple and powerful in JavaScript applications.