Javascript Array descriptiveText()

Description

Javascript Array descriptiveText()


Array.prototype.descriptiveText = function () {
    var n = this.length;
    switch (n) {//from  w  ww .jav a 2s.  c  o m
        case  0: return '[] is an empty array';
        case  1: return JSON.stringify(this) + ' is an array with 1 element';
        default: return JSON.stringify(this) + ' is an array with ' + n + ' elements';
    }
}



PreviousNext

Related