Wednesday, February 21, 2024

TITLE CASE VANILLA JS

 <script>
function titleCase(title, minorWords) {
  if (title.length === 0) return title;
  var words = title.toLowerCase().split(" ");
  var minorWordsArray = minorWords ? minorWords.toLowerCase().split(" ") : [];
  return words
    .map(function (word, index) {
      if (minorWordsArray.indexOf(word) !== -1 && index != 0) {
        return word;
      }
      return word.charAt(0).toUpperCase() + word.slice(1);
    })
    .join(" ");
}
</script>

No comments:

Post a Comment

Set Cookie dan Remove Cookie dengan php vanilla.js

< html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport...