| Viewed 88 times

How to get Number of Arrays in an Array in JavaScript?


I need to Create a function that Returns the total number of arrays inside a given array.

1 Answer
Mohammad Qandeel
Answered
10

 

function numOfSubbarrays(arr) {
 return arr.filter(a => a instanceof Array).length;
}

Example

numOfSubbarrays([[],[],[],[],[]]) // 5

 


Related Questions