Unicode

String.prototype.toUnicode = function(){
    var result = "";
    for(var i = 0; i < this.length; i++){
        result += "\\u" + ("000" + this[i].charCodeAt(0).toString(16)).substr(-4);
    }
    return result;
};

var output = input.toUnicode();

UTF-8

var output = encodeURI(input);

stackoverflow