Below is a sample on how to extends an array object.
Array.prototype.getMinValue = function(){
var minIndex = 0;
for(i=1;i<this.length;i++){
if(this[i]<this[minIndex]){
minIndex = i;
}
}
return this[minIndex]
}
var minIndex = 0;
for(i=1;i<this.length;i++){
if(this[i]<this[minIndex]){
minIndex = i;
}
}
return this[minIndex]
}
You can call the above method by:
var data = [5,4,8,3,1,6];
alert(data.getMinValue());
output>> 1
No comments:
Post a Comment