Javascript Data Type How to - Test if array is multidimensional








Question

We would like to know how to test if array is multidimensional.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--   w ww.j ava  2 s  .  c o m-->
var ratings = [[1], [2], 'test'];
document.writeln( ratings.filter(Array.isArray).length );

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: