JavaScript Array Reference
JavaScript Array is used to store multiple elements in a single variable. It is often used when we want to store a list of elements and access them by a single variable. Unlike most languages where the array is a reference to the multiple variables, in JavaScript array is a single variable that stores multiple elements.
Syntax:
const arr = ["Item1", "Item2", "Item3", ...];
Example: In this example, we are creating an array and copying its items to another array, and displaying its items.
JavaScript
<script> // Create and initialize an array let items = ['GFG', 'Geeks', 'G4G']; // Display the array items console.log(items); // Create a new empty array let new_Array = []; // forEach loop to push elements // into new array items.forEach(function (item) { new_Array.push(item); }); // Display the new array of items console.log(new_Array);</script> |
Output:
Original Array: GFG, Geeks, G4G Copied Array: GFG, Geeks, G4G
Array Methods: The complete list of JavaScript Array methods are listed below.
JavaScript Array Methods | Descriptions |
|---|---|
| JavaScript Array concat() Method | The arr.concat() method is used to merge two or more arrays together. |
| JavaScript Array copyWithin() Method | The Array.copyWithin() method considers an array first and then copies part of an array to the same array itself and returns |
| JavaScript Array entries() Method | JavaScript Array.entries() method works on iterable objects such as an array (or any data iterable data structure) and it is used to fetch all the entries of the same data structure. |
| JavaScript Array every() Method | This method considers all the elements of an array and then further checks that whether all the elements of the array satisfy the given condition (passed by in user) or not that is provided by a method passed to it as the argument. |
| JavaScript Array fill() Method | The arr.fill() method is used to fill the array with a given static value. |
| JavaScript Array filter() Method | The arr.filter() method is used to create a new array from a given array consisting of only those elements from the given array which satisfy a condition set by the argument method. |
| JavaScript Array find() Method | The arr.find() method in Javascript is used to get the value of the first element in the array that satisfies the provided condition. |
| JavaScript Array findIndex() Method | The Array.findIndex() method is used to return the first index of the element in a given array that satisfies the provided testing function (passed in by the user while calling). |
| JavaScript Array flat() Method | The arr.flat() method was introduced in ES2019. It is used to flatten an array, to reduce the nesting of an array. |
| JavaScript Array flatMap() Method | The array.flatMap() is an inbuilt function in JavaScript that is used to flatten the input array element into a new array. |
| JavaScript Array forEach() Method | The arr.forEach() method calls the provided function once for each element of the array. |
| JavaScript Array from() Method | The JavaScript Array from() method returns an Array object from any object with a length property or an iterable object. |
| JavaScript Array includes() Method | The array.includes() method is used to know either a particular element is present in the array or not and accordingly, it returns true or false i.e, if the element is present, then it returns true otherwise false. |
| JavaScript Array indexOf() Method | The arr.indexOf() method is used to find the index of the first occurrence of the search element provided as the argument to the method |
| JavaScript Array isArray() Method | The arr.isArray() method determines whether the value passed to this function is an array or not. This function returns true if the argument passed is an array else it returns false |
| JavaScript Array join() Method | The arr.join() method is used to join the elements of an array into a string. |
| JavaScript Array keys() Method | The array.keys() method is used to return a new array iterator which contains the keys for each index in the given input array. |
| JavaScript Array lastIndexOf() Method | The arr.lastIndexOf() method is used to find the index of the last occurrence of the search element provided as the argument to the function. |
| JavaScript Array map() Method | The arr.map() method creates a new array with the results of a called function for every array element. This function calls the argument function once for each element of the given array in order. |
| JavaScript Array.of() Method | The array.of() function is an inbuilt function in JavaScript that creates a new array instance with variables present as the argument of the function. |
| JavaScript Array pop() Method | The arr.pop() method is used to remove the last element of the array and also returns the removed element. This function decreases the length of the array. |
| JavaScript Array push() Method | The arr.push() method is used to push one or more values into the array. This method changes the length of the array by the number of elements added to the array. |
| JavaScript Array reduce() Method | It is used to reduce the array to a single value and executes a provided function for each value of the array (from left-to-right) and the return value of the function is stored in an accumulator. |
| JavaScript Array reduceRight() Method | The arr.reduceRight() method in JavaScript is used to convert elements of the given array from right to left to a single value. |
| JavaScript Array reverse() Method | The arr.reverse() method is used for the in-place reversal of the array. The first element of the array becomes the last element and vice versa. |
| JavaScript Array shift() Method | The arr.shift() method removes the first element of the array thus reducing the size of the original array by 1 |
| JavaScript Array slice() Method | The arr. slice() method returns a new array containing a portion of the array on which it is implemented. The original remains unchanged. |
| JavaScript Array some() Method | The arr.some() method checks whether at least one of the elements of the array satisfies the condition checked by the argument method. |
| JavaScript Array sort() Method | The arr.sort() method is used to sort the array in place in a given order according to the compare() function. If the method is omitted then the array is sorted in ascending order. |
| JavaScript Array splice() Method | JavaScriptthat arr.splice() method is an inbuilt method in JavaScript that is used to modify the contents of an array by removing the existing elements and/or by adding new elements. |
| JavaScript Array toLocaleString() Method | The array.toLocaleString() is an inbuilt function in JavaScript which is basically used to convert the elements of the given array to string. |
| JavaScript Array toString() Method | The role of this method is to return the string representation of the array elements. |
| JavaScript Array unshift() Method | This is used to add one or more elements to the beginning of the given array. This function increases the length of the existing array by the number of elements added to the array. |
| JavaScript Array values() Method | JavaScript array.values() function is an inbuilt function in JavaScript that is used to return a new array Iterator object that contains the values for each index in the array i.e, it prints all the elements of the array. |
Array Property: The list of JavaScript Array properties are listed below.
JavaScript Array Property | Description |
|---|---|
| JavaScript Array constructor Properties | The JavaScript Array constructor property is used to return the constructor function for an array object. It only returns the reference of the function and does not returns the name of the function. |
| JavaScript Array length property | The array length property in JavaScript is used to set or return the number of elements in an array. |
JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples.






Please Login to comment...