Count elements of a JavaScript-object
Snippet for counting elements of a javascript-object.
var oTestObject = new Object();
oTestObject['element1'] = "Wert1";
oTestObject['element2'] = "Wert2";
oTestObject['element3'] = "Wert3";
oTestObject['element4'] = "Wert4";
Object.getLength = function(oTmpObject)
{
var iLength = 0;
for (var sKey in oTmpObject)
{
if (oTmpObject.hasOwnProperty(sKey)) iLength++;
}
return iLength;
};
var iLength = Object.getLength(oTestObject); //4
Url: http://sklueh.de/2012/09/anzahl-der-elemente-eines-objekts-in-javascript-ermitteln/
Language: JavaScript | User: sklueh | Created: Sep 24, 2013