javascript string prototype 1

javascript string prototype

/* String prototype all built-in methods:
 * -------------------------------------------------------------------------

// Example for *extending* the String prototype
String.prototype.reduce = function () { 
    return this.split().reduce(...arguments);

Here is what the above code is Doing:
1. We’re creating a new function called reduce on the String prototype.
2. We’re using the split method to split the string into an array.
3. We’re using the reduce method on the array to reduce the array to a single value.

Similar Posts