00 Votes

JavaScript: Get Array Length

Question by PC Control | 2014-05-22 at 11:12

Currently, I am trying to determine the length of an array in JavaScript.

Unfortunately, neither length(arr) nor count(arr) are working for me.

Can someone help me how to get the number of elements in a JavaScript array?

ReplyPositiveNegative
0Best Answer0 Votes

In JavaScript, every array has the property "length" with which you can determine the length:

var arr = [1, 2, 3];
var len = arr.length;
alert(len);  // 3

Or for two-dimensional arrays:

var arr = [[1, 2, 3], [1, 2, 3]];

for(var i in arr) {
  alert(arr[i].length);
}

With count(arr), you can get the array length in PHP.
2014-05-22 at 16:32

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.