JSFiddle - React, Tailwind, and code Playground
by Denis
JavaScript
function trim(str, chars) {
return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
var a=[" бердяев","Афанасенко"," савельев "];
document.write("Input:<br>"); document.write(a+"<br><br>");
for(var x in a){
var str = trim(a[x]);
var first = str.substr(0,1).toUpperCase();
a[x] = first + str.substr(1);
}
document.write("Output:<br> "+a);