programming-examples/js/String/Convert a string in abbreviated form.js
2019-11-15 12:59:38 +01:00

8 lines
282 B
JavaScript

abbrev_name = function (str1) {
var split_names = str1.trim().split(" ");
if (split_names.length > 1) {
return (split_names[0] + " " + split_names[1].charAt(0) + ".");
}
return split_names[0];
};
console.log(abbrev_name("Robin Singh"));