Implementation of JavaScript array length property


Took 12 minutes 48 seconds to implement JavaScript array length property. The maximum length of the array can only be 10000. Here is the code snippet.

Function:
arr = ['1', '2', '3', '4'];
count = 0;
function length(arr) {
for (var i = 0; i < 10000; i++) {
if(arr[i] != undefined) {
count++;
}
}
return count;
}

document.write(length(arr));

Result:
4

No comments:

Post a Comment

GITEX Dubai Talk by Saion Gupta and Saiasmi Gupta

Good morning, everyone. I'm Saion Gupta, the Founder of 10xCoderKids and the Guinness World Record holder for the youngest computer prog...