1.var key = 'a_b';this
var a = key.replace(/\b.|_./g, function (i) {
if (i.length === 2) {
i = ' ' + i[1];
}
return i.toUpperCase();
});server
2.先去除下劃線,再將首字母大寫,再用substring方法,最後用join,like this:string
var array = key.split('_');it
for (var i = 0; i < array.length; i++) {
array[i] = array[i][0].toUpperCase() + array[i].substring(1, array[i].length);
}
var servertype = array.join(' ');io