Posted By

arunpjohny on 11/05/09


javascript array

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Array.size function

 / Published in: JavaScript

This can be tested using the following piece of code

    var a = [1, 2, 3, 4, 5];
  1. if(typeof Array.prototype.size != 'function'){
  2. Array.prototype.size = function(){
  3. return this.length;
  4. }
  5. }

Report this snippet  


RSS Icon Subscribe to comments
Posted By: MMDeveloper on November 6, 2009

just an honest question, why would one go through the trouble of adding this method when it simple aliases a property? Typing the property name "length" and the method call "size()" are both 6 characters long and therefor save the user no typing.

You need to login to post a comment.