Title of the first letter of sentiment in JavaScript / jQuery

This is a test. this is another test. and this is also a new test.

This is a test. This is another test. And this is a new test.

0
source share
1 answer

You do not need jQuery for this. You can use Javascript stringand functions array.

  • Divide the line by .to separate different sentences
  • Trim each sentence
  • First letter title
  • Join to .

var str = 'this is a test. this is one more test. and this also new test.';

var newStr = str.split('.').map(function(el) {
  el = el.trim();
  return el.substr(0, 1).toUpperCase() + el.substr(1);
}).join('. ');

alert(newStr.trim());
Run codeHide result
+2
source

Source: https://habr.com/ru/post/1599306/


All Articles