JavaScript - Length of an Array in JS Last Updated : 12 Nov, 2024 Suggest changes Share Like Article Like Report These are the following approaches to find the length of the given array: 1. Using length Property - Mostly UsedIn this approach, we have used the length property to determine the length of an array. JavaScript let a = [12, 4.7, 9, 10] console.log(a.length) Output4 2. Using for of and for in LoopWe have used for of and for in loops to traverse each element of the array and increment a counter variable. we have defined an array 'a' and initializes a variable size to 0. It then iterates over the elements of the array using both for-in and for-of loops, incrementing size for each element. Finally, it prints the lengths obtained from both loops. JavaScript let a = [12, 4.7, 9, 10] let s = 0; for (let element in a) { s++; } console.log(s) s = 0; for (let element of a) { s++; } console.log(s) Output4 4 3. Using reduce() MethodThe reduce() method can be used to count the number of elements in the array by incrementing a counter for each element. JavaScript let a = [12, 4.7, 9, 10]; console.log(a.reduce((size) => size + 1, 0)); Output4 Advertise with us Next Article JavaScript - Length of an Array in JS A ameyabavkar Follow Similar Reads JavaScript Program to Create an Array with a Specific Length and Pre-filled Values In JavaScript, we can create an array with a specific length and pre-filled values using various approaches. This can be useful when we need to initialize an array with default or placeholder values before populating it with actual data.Table of ContentMethod 1: Using the Array() Constructor and fil 3 min read JavaScript Program to find the Longest Consecutive Sequence of Numbers in an Array In this article, we are going to find the longest consecutive sequence of numbers in an array using JavaScript language. We are given an array that consists of integers we need to find the longest subsequence such that elements in the subsequence are consecutive integers, these numbers are in any or 4 min read JavaScript Program to find Length of Linked List using JavaScript Given a linked list, the task is to determine its length using various methods. The linked list is a fundamental data structure consisting of nodes connected in a chain, offering efficient data organization. Different approaches, including Iterative and Recursive Methods, enable us to compute the le 3 min read JavaScript Program to Count the Number of Keys/Properties in an Object An object consists of key-value pairs where each key is a unique identifier associated with a corresponding value. Several methods can be used to count the number of keys/properties in an object, which are listed below: Table of Content Counting the Number of Keys using Object.keysCounting the Numbe 4 min read JavaScript Program to Find the length of the Longest Continuous Decreasing Subarray Given an array of numbers, our task is to find the length of the longest continuous subarray where the numbers are strictly decreasing. Example: Input:const arr = [7, 4, 7, 6, 5, 4, 6, 8, 9]Output: 4Explanation: The longest continuous decreasing subarray in this array is [7, 6, 5, 4], and its length 3 min read Article Tags : JavaScript Web Technologies javascript-array JavaScript-DSA JavaScript-Program +1 More Like