Open In App

JavaScript Array Programming Examples

Last Updated : 06 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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, an array is a single variable that stores multiple elements.

Syntax:

let array = [value1, value2, ...];
let array = new Array();

Example 1: Here is the basic example of an array in javascript.

Javascript




// Declaring an array using Literal Notation
let language = ["HTML","CSS","Javascript"]
console.log(language)


Output:

['HTML', 'CSS', 'Javascript']

Example 2: In this example, we are using a new keyword.

Javascript




// Declaring an array using Array Constructor
let language = new Array(3)
language[0] = "HTML"
language[1] = "CSS"
language[2] = "Javascript"
console.log(language)


Output:

['HTML', 'CSS', 'Javascript']

The following section contains a wide collection of javascript Array examples. Many of these program examples offer different ways to handle the issue.

Javascript Array Question:

1 Create an Array of Given Size in JavaScript
2 How to Initialize an Array in JavaScript ?
3 Ways of Iterating Over an Array in JavaScript
4 Most Efficient Way to Create a Zero Filled Array in JavaScript
5 JavaScript Program to Create an Array with a Specific Length and Pre-filled Values
6 How to Check if an Array includes a Value in JavaScript?
7 JavaScript Program to Access Elements in an Array
8 JavaScript Program to Determine the Length of an Array
9 Check if an Element is Present in an Array using JavaScript
10 JavaScript Program to Swap First and Last Elements in an Array
11 Different Ways to Populate an Array in JavaScript
12 JavaScript Program to Delete Middle Element from an Array
13 Different Ways to Delete an Item from an Array using JavaScript
14 Copy Array Items into Another Array in JavaScript
15 How to Copy Array by Value in JavaScript ?
16 How to Clone an Array in JavaScript ?
17 How to Fill an Array with Given Value in JavaScript ?
18 JavaScript Program to Create an Array of Unique Values From Multiple Arrays Using Set Object
19 Create Array of Integers Between Two Numbers Inclusive in JavaScript
20 How to Find the Array Index with a Value in JavaScript ?
21 JavaScript Program to find the Nth smallest/largest element from an unsorted Array
22 How to Add Elements to the End of an Array in JavaScript ?
23 JavaScript Program to Find Second Largest Element in an Array
24 JavaScript Program to Find the Largest Three Elements in an Array
25 Javascript Program to Find the Largest Element in an Array
26 JavaScript Program to Find Next Smaller Element
27 JavaScript Program to Check if an Array Contains only Unique Values
28 How to create an array containing 1…N numbers in JavaScript ?
29 JavaScript Program to Reorder an Array According to Given Indexes
30 How to Check a Value Exist at Certain Array Index in JavaScript ?
31 JavaScript Program to Find the Missing Number in a Given Integer Array of 1 to 100
32 JavaScript Program to Find the Most Frequent Element in an Array
33 JavaScript Program to Construct an Array from its pair-sum Array
34 Best Way to Find an Item in an Array in JavaScript
35 How to Calculate the Cumulative Sum of Elements in an Array using JavaScript ?
36 JavaScript Program to Find Index of First Occurrence of Target Element in Sorted Array
37 JavaScript Program to Check an Array is Sorted or Not
38 How to Remove Smallest and Largest Elements from an Array in JavaScript ?
39 How to Create an Array of Cumulative Sum in JavaScript ?
40 How to Change Values in an Array when Doing foreach Loop in JavaScript ?
41 How to get first N number of elements from an array in JavaScript ?
42 What is the most efficient way to concatenate N arrays in JavaScript ?
43 How to merge two arrays and remove duplicate items in JavaScript ?
44 How to Merge/Flatten an array of arrays in JavaScript ?
45 Different ways to search an item in an array in JavaScript
46 Count occurrences of all items in an array in JavaScript
47 Count Frequency of an Array Item in JavaScript
48 Javascript program for counting frequencies of array elements
49 How to Create an Array using Intersection of two Arrays in JavaScript ?
50 Reverse an array in JavaScript
51 Creating a Zero-Filled Array in JavaScript
52 How to find the sum of all elements of a given array in JavaScript ?
53 Calculate the length of an associative array using JavaScript
54 How to Remove duplicate elements from array in JavaScript ?
55 How to filter out the non-unique values in an array using JavaScript ?
56 How to remove elements of a given array until the passed function returns true in JavaScript ?
57 How to remove specific elements from the left of a given array of elements using JavaScript ?
58 How to count number of occurrences of repeated names in an array of objects in JavaScript ?
59 How to remove falsy values from an array in JavaScript ?
60 How to move specified number of elements to the end of an array in JavaScript ?
61 How to flatten a given array up to the specified depth in JavaScript ?
62 How to get the standard deviation of an array of numbers using JavaScript ?
63 How to get symmetric difference between two arrays in JavaScript ?
64 How to get n largest elements from array in JavaScript ?
65 How to find every element that exists in any of two given arrays once using JavaScript ?
66 Find all elements in a array except for the first one using JavaScript ?
67 How to remove n elements from the end of a given array in JavaScript ?
68 How to create an object from two arrays in JavaScript?
69 How to create a string by joining the elements of an array in JavaScript ?
70 How to splice an array without mutating the original Array?
71 Swapping two array elements in a single line using JavaScript
72 How to create HTML list from JavaScript array ?
73 How to get the same value from another array
and assign to object of arrays ?
74 JavaScript Program to Sort Words in Alphabetical Order
75 JavaScript Program to Sort an Array which Contain 1 to n Values
76 JavaScript Program to find the Longest Consecutive Sequence of Numbers in an Array
77 How to create an array containing non-repeating elements in JavaScript ?
78 How to print unique elements from two unsorted arrays using JavaScript ?
79 How to remove Objects from Associative Array in JavaScript ?
80 JavaScript Program to Rearrange Array such that Even Positioned are Greater than Odd
81 JavaScript Program to Merge two Sorted Arrays into a Single Sorted Array
82 JavaScript Program to Determine the Frequency of Elements in an Array and Represent it as an Object
83 Difference between sorting string array and numerical array
84 How to loop through an array containing multiple objects and access their properties in JavaScript ?
85 How to create an array of partial objects from another array in JavaScript ?
86 How to create an array of objects from multiple arrays in JavaScript ?
87 How to group objects in an array based on a common property into an array of arrays in JavaScript ?
88 How to modify an object’s property in an array of objects in JavaScript ?
89 How to create an array of elements, ungrouping the elements in an array produced by zip in JavaScript ?
90 Convert an array of objects to a CSV string that contains only the columns specified using JavaScript
91 How to use arrays to swap variables in JavaScript ?
92 How to fill static values in an array in JavaScript ?
93 What are the Important Array Methods of JavaScript ?
94 How to filter an array of objects in ES6 ?
95 How to remove duplicate elements from JavaScript Array ?
96 Difference between Array and Array of Objects in JavaScript
97 Difference between forEach() and map() loop in JavaScript
98 JavaScript Program to Rearrange Array Alternately
99 JavaScript Program for the Minimum Index of a Repeating Element in an Array
100 How to convert CSV string file to a 2D array of objects using JavaScript ?
101 JavaScript Program to find Smallest Difference Triplet from Three Arrays
102 JavaScript Program to Find Shortest Distance Between Two Words in an Array of Words
103 JavaScript Program to find the Index of Last Occurrence of Target Element in Sorted Array
104 How to filter values from an array for which the comparator function does not return true in JavaScript ?
105 How many numbers in the given array are less/equal to the given value using the percentile formula ?
106 What’s the difference between toArray and makeArray in jQuery ?
107 How to convert a 2D array to a comma-separated values (CSV) string in JavaScript ?
108 Best-Known JavaScript Array Methods
109 How to truncate an array in JavaScript ?
110 How to print object by id in an array of objects in JavaScript ?
111 How to convert a number into array in JavaScript ?
112 How to use Array.prototype.reduce() method in JavaScript ?
113 How to convert two-dimensional array into an object in JavaScript ?
114 How to count number of data types in an array in JavaScript ?
115 How to transform a JavaScript iterator into an array ?
116 How to add elements to an existing array dynamically in JavaScript ?
117 How to search the max value of an attribute in an array object ?
118 How to move an array element from one array position to another in JavaScript?
119 How to detect the duplication of values of input fields ?
120 How to call the map method only if the element is an array?
121 Dense and Sparse Array in JavaScript
122 Remove Array Element Based on Object Property in JavaScript
123 Short Circuit Array.forEach Like Calling Break
124 Sort array of objects by single key with date value in JavaScript
125 Check an array of strings contains a substring in JavaScript
126 How to extend an existing array with another array without creating a new array in JavaScript ?
127 Set vs Array in JavaScript
128 How to access and process nested objects, arrays, or JSON ?
129 Is JavaScript Array Sort Stable ?
130 How to store an array in localStorage ?
131 How to Sort Numeric Array using JavaScript ?
132 Find the OR and AND of Array elements using JavaScript
133 Find all the combinations of the array values in JavaScript
134 How to use map() on an array in reverse order with JavaScript ?
135 How to convert Integer array to String array using JavaScript ?
136 How to make Array.indexOf() case insensitive in JavaScript ?
137 How to sort an array of object by two fields in JavaScript ?
138 Remove elements from a JavaScript Array
139 How to convert an Object {} to an Array [] of key-value pairs in JavaScript?
140 How to check whether an array is subset of another array using JavaScript ?
141 How to compute union of JavaScript arrays ?
142 How to find the index of all occurrence of elements in an array using JavaScript ?
143 How to compare two JavaScript array objects using jQuery/JavaScript ?
144 How to remove multiple elements from array in JavaScript ?
145 How to remove duplicates from an array of objects using JavaScript ?
146 How to select a random element from array in JavaScript ?
147 How to store all dates in an array present in between given two dates in JavaScript ?
148 How to unpack array elements into separate variables using JavaScript ?
149 How to select Min/Max dates in an array using JavaScript ?
150 Get the Difference between Two Sets using JavaScript
151 How to replace an item from an array in JavaScript ?
152 How to check all values of an array are equal or not in JavaScript ?
153 How to convert Map keys to an array in JavaScript ?
154 How to add an object to an array in JavaScript ?
155 How to get a list of associative array keys in JavaScript ?
156 Convert comma separated string to array using JavaScript
157 Max/Min value of an attribute in an array of objects in JavaScript
158 How to find if two arrays contain any common item in Javascript ?
159 Remove the last item from an array in JavaScript
160 Find the min/max element of an Array using JavaScript
161 Delete the array elements in JavaScript | delete vs splice
162 Split an array into chunks in JavaScript
163 How to get character array from string in JavaScript ?
164 How to convert Set to Array in JavaScript ?
165 Convert an Array to an Object in JavaScript
166 How to insert an item into array at specific index in JavaScript ?
167 Create a comma separated list from an array in JavaScript
168 JavaScript Get all non-unique values from an array
169 Sort an Object Array by Date in JavaScript
170 How to use loop through an array in JavaScript ?
171 How to get all unique values (remove duplicates) in a JavaScript array?
172 How to compare two arrays in JavaScript ?
173 Get the first and last item in an array using JavaScript
174 How to check if a variable is an array in JavaScript?
175 Remove empty elements from an array in JavaScript
176 How to empty an array in JavaScript ?
177 Add new elements at the beginning of an array using JavaScript
178 JavaScript Program to Split Map Keys and Values into Separate Arrays
179 How to remove an element from an array in JavaScript?
180 How to append an element in an array in JavaScript ?
181 Implementation of Array class in JavaScript
182 How to Convert Byte Array to String in JavaScript ?
183 How to Get the Difference Between Two Arrays in JavaScript ?
184 JavaScript Program to Sort an Associative Array by its Values
185 Map to Array in JavaScript
186 String to Array in JavaScript
187 How to Sort an Array using JavaScript when Array Elements has Different Data Types ?
188 Destructive vs Non-Destructive Approach in JavaScript Arrays
189 JavaScript Program for Left Rotate by One in an Array
190 JavaScript Program to Convert Byte Array to JSON
191 Find the Rotation Count in Rotated Sorted array in JavaScript
192 Converting JavaScript Arrays into CSVs and Vice-Versa
193 JSON Modify an Array Value of a JSON Object
194 JavaScript Program for Finding the Majority Element of an Array
195 JavaScript Program to Find k Most Occurrences in the Given Array
196 What are Associative Arrays in JavaScript ?
197 JavaScript Program to Count Unequal Element Pairs from the Given Array
198 JavaScript Program to Find Union and Intersection of Two Unsorted Arrays
199 JavaScript Program to Find Largest Subarray with a Sum Divisible by k
200 JavaScript Program to Find the First Non-Repeated Element in an Array
201 JavaScript Program to Convert an Array into a String
202 JavaScript Program to Find Median in a Stream of Integers (running integers) using Array
203 JavaScript Progam to rearrange an array in maximum minimum form using Two Pointer Technique
204 JavaScript Program to Find Index of an Object by Key and Value in an Array
205 Sparse Table Using JavaScript Array
206 JavaScript Program to Merge Two Arrays Without Creating a New Array
207 JavaScript Program for K-th Largest Sum Contiguous Subarray
208 JavaScript Program to Find the Most Frequently Occurring Element in an Array
209 Map() vs Filter() in Javascript
210 JavaScript Program to Find Maximum Profit by Buying and Selling a Share at Most Twice
using Array
211 How does Array.prototype.slice.call work in JavaScript ?
212 Square Root (Sqrt) Decomposition Algorithm Using JavaScript Array
213 Prevention from getting error by adding script tag anywhere using
DOMContentLoaded Event Listener of
JavaScript
214 Arrays in JavaScript behaves like an Object
215 How to extract value of a property as array from an array of objects ?
216 How to get distinct values from an array of objects in JavaScript?
217 How to pass array in another array of objects?
218 How to sort an array of objects by property values ?
219 How to Declare Two Dimensional Empty Array in JavaScript ?
220 How to create two dimensional array in JavaScript ?
221 JavaScriptProgram to Check Two Matrices are Identical or Not
222 JavaScript Program to Find Sum of elements in a Matrix
223 Transpose a two dimensional (2D) array in JavaScript
224 JavaScript Program for Selection Sort
225 JavaScript Program for Insertion Sort
226 JavaScript Program for Merge Sort
227 JavaScript Program for Quick Sort
228 Shell Sort Visualizer using JavaScript

We have a complete list of Javascript Array functions, to check those please go through this JavaScript Array Complete Reference article.

We have created an article of JavaScript Examples, and added list of questions based on Array, Object, Function, …, etc. Please visit this JavaScript Examples to get complete questions based articles list of JavaScript.

We have created a complete JavaScript Tutorial to help both beginners and experienced professionals. Please check this JavaScript Tutorial to get the complete content from basic syntax and data types to advanced topics such as object-oriented programming and DOM manipulation.

Recent articles on JavaScript



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads