If it is necessary to be able to perform manipulations on your string as if it were an array or chars, that you perhaps create some prototypes:
String.prototype.splice = function(start,length,insert) {
var a = this.slice(0, start);
var b = this.slice(start+length, this.length);
if (!insert) {insert = "";};
return new String(a + insert + b);
};
String.prototype.push = function(insert) {
var a = this
return new String(a + insert);
};
String.prototype.pop = function() {
return new String(this.slice(0,this.length-1));
};
String.prototype.concat = function() {
if (arguments.length > 0) {
var string = "";
for (var i=0; i < arguments.length; i++) {
string += arguments[i];
};
return new String(this + string);
};
};
String.prototype.sort = function(funct) {
var arr = [];
var string = "";
for (var i=0; i < this.length; i++) {
arr.push(this[i]);
};
arr.sort(funct);
for (var i=0; i < arr.length; i++) {
string += arr[i];
};
return new String(string);
};
var a = new String("hello");
var b = a.splice(1,1,"b");
var c = a.pop();
var d = a.concat(b,c);
var e = a.sort();
returns hello,
hbllo,
hell, hellohbllohell, ehllo