javascript - edit array elements and capitalize the letters -
i have array
var myarr = [ "color - black", "color - blue", "color - red" ]
i want replace " - " ":" , capitalize first letter
var myarr = [ "color: black", "color: blue", "color: red" ]
i try don't know how capitalize first letter
for(var i=0; < myarr.length; i++) { myarr[i] = myarr[i].replace(/ - /g, ":"); }
try this:
var myarr = [ "color - black", "color - blue", "color - red" ] for(var i=0; < myarr.length; i++) { myarr[i] = myarr[i][0].touppercase() + myarr[i].replace(/ -/g, ":").substring(1); } console.log(myarr);
Comments
Post a Comment