count() in JavaScript
Array.prototype.count = function() { return this.length; };
Sample :
var v_array = [ 5, 10, 15, 20, 25]; document.writeln(v_array.count()); // 5
Source: AB-D.fr
DZone Snippets > ki4ngel > array
11384 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Benoit Asselin http://www.ab-d.fr
Array.prototype.count = function() { return this.length; };
var v_array = [ 5, 10, 15, 20, 25]; document.writeln(v_array.count()); // 5
Array.prototype.in_array = function(p_val) { for(var i = 0, l = this.length; i < l; i++) { if(this[i] == p_val) { return true; } } return false; }
var v_array = [ 5, 10, 15, 20, 25]; document.writeln(v_array.in_array(10)); // true document.writeln(v_array.in_array(11)); // false