Javascript Array trim()

Description

Javascript Array trim()



'use strict';//from  ww  w.  j a  v a  2 s. c  o m

/**
 * @returns {Array}
 */
Array.prototype.trim = function () {
    return this.map (Function.prototype.call, String.prototype.trim);
}; // trim ();

Javascript Array trim()

/**//from   ww w .j ava2  s. co m
 * Utility function to trim an array from empty strings. It will also not copy over the functions
 */
Array.prototype.trim = function () {
    var newArray = [];
    for (var key in this) {
        if (typeof(this[key]) != 'undefined' && this[key] != '') {
            if (typeof this.__proto__[key] == "undefined" || this[key] != this.__proto__[key]) {
                newArray.push(this[key]);
            }
        }
    }
    return newArray;
};



PreviousNext

Related