I have an array
var myarr = [ "color - black", "color - blue", "color - Red" ]
And I want want to replace " - " with ":" and capitalize the first letter of every word in that array:
var myarr = [ "Color: Black", "Color: Blue", "Color: Red" ]
I try
for (var i = 0; i < myarr.length; i++) {
myarr[i] = myarr[i][0].toUpperCase()+myarr[i].replace(/ -/g, ":").substring(1);
}
But it works only for the first word
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…