How to Get the Size of an Array in JavaScript Last Updated : 29 Oct, 2024 Comments Improve Suggest changes Like Article Like Report To get the size (or length) of an array in JavaScript, we can use array.length property. The size of array refers to the number of elements present in that array. Syntaxconst a = [ 10, 20, 30, 40, 50 ] let s = a.length; // s => 5 The JavaScript Array Length returns an unsigned integer value that represents the number of elements present in the array. The value is non-negative and always a 32-bit integer. JavaScript // Defining an array const a = [ 10, 20, 30, 40, 50 ] // Storing length of array let l = a.length; // Displaying the length of arr1 console.log("Length of the Array is:", l); OutputLength of the Array is: 5 Get the Size of an Array using array.reduce() MethodThe reduce() method iterates over each element of an array, accumulating a value based on a callback function. To get the size of an array, reduce() increments an accumulator for each element, returning the final count.Syntaxconst size = array.reduce((acc) => acc + 1, 0); JavaScript // Defining an array const a = [ 10, 20, 30, 40, 50 ] // Iterating with initial value 0 const s = a.reduce((acc) => acc + 1, 0); console.log("The size of the given array is:", s); OutputThe size of the given array is: 5 Get the Size of an Array using for...of LoopWe can use the for...of loop to count elements manually by incrementing a counter. JavaScript const a = [1, 2, 3, 4, 5]; let c = 0; for (let element of a) { c++; } console.log(c); Output5 Comment More infoAdvertise with us Next Article How to Get the Size of an Array in JavaScript T tridibbag56 Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies Technical Scripter 2022 JavaScript-Questions +1 More Similar Reads How to Get the Longest String in an Array using JavaScript? Given an array, the task is to get the longest string from the array in JavaScript. Here are a few of the most used techniques discussed with the help of JavaScript. In this article, we will use JavaScript methods to find out the longest string in the array. All approaches are described below with e 5 min read How to Find the Length of an Array in JavaScript ? JavaScript provides us with several approaches to count the elements within an array. The length of an array lets the developer know whether an element is present in an array or not which helps to manipulate or iterate through each element of the array to perform some operation. Table of Content Usi 3 min read How to get the size of a JavaScript object ? In this article, we will see the methods to find the size of a JavaScript object. These are the following ways to solve the problem: Table of Content Using Object.keys() methodUsing Object.objsize() methodUsing Object.entries() methodUsing Object.values() methodUsing Object.keys() methodWe can get t 2 min read Create an Array of Given Size in JavaScript The basic method to create an array is by using the Array constructor. We can initialize an array of certain length just by passing a single integer argument to the JavaScript array constructor. This will create an array of the given size with undefined values.Syntaxconst arr = new Array( length );J 3 min read How to Find the Sum of an Array of Numbers in JavaScript ? To find the sum of an array of numbers in JavaScript, you can use several different methods.1. Using Array reduce() MethodThe array reduce() method can be used to find the sum of array. It executes the provided code for all the elements and returns a single output.Syntaxarr.reduce( callback( acc, el 2 min read Like