var output = '565^23';
for(var i=0, l=output.length; i<l; i++){
if(output[i]=='^' && i>0 && i<l-1){
output[i]='Math.pow('+output[i-1]+','+output[i+1]+')';
output[i-1]='';
if(i>=l-2 || output[i+2]!=='^'){
output[i+1]='';
}
i++;
}}
alert(output);
var output = '565^23'.split('');
for (var i = 0, l = output.length; i < l; i++) {
if (output[i] == '^' && i > 0 && i < l - 1) {
output[i] = 'Math.pow(' + output[i - 1] + ',' + output[i + 1] + ')';
output[i - 1] = '';
if (i >= l - 2 || output[i + 2] !== '^') {
output[i + 1] = '';
}
i++;
}
}
alert(output.join(''));