Last Updated: February 25, 2016
·
591
· ashnur

Javascript stringSplice

void function(root){

    var splice = Array.prototype.splice;

    function toString(value){ return String(value || '') }

    function toArray(val){ return toString(val).split('') }

    function stringSplice(original, from, length, change){

        var org = toArray(original)
            , chg = toArray(change)

        splice.apply(org, [from, length].concat(chg)).join('')
        return org 
    }   

    module.exports = stringSplice

}(this) 

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside