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

Coding for Kids

What is coding? In coding we build a program to do a specific task for us. Code: A code is a set of computer instructions and when you will ...