GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Sunday, January 2, 2011

Extending Array Object

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]
}

You can call the above method by:
var data = [5,4,8,3,1,6];
alert(data.getMinValue());
output>> 1
       

Share/Bookmark

No comments:

Post a Comment