something case js code example
Example 1: string to title case javascript
function titleCase(sentence) {
let sentence = string.toLowerCase().split(" ");
for (let i = 0; i < sentence.length; i++) {
sentence[i] = sentence[i][0].toUpperCase() + sentence[i].slice(1);
}
return sentence.join(" ");
}
Example 2: compare string camelcase and lowercase javascript
function sameCase(str) {
return /^[A-Z]+$/.test(str) || /^[a-z]+$/.test(str);
}
Example 3: compare string camelcase and lowercase javascript
var haystack = "A. BAIL. Of. Hay.";
var needle = "bail.";
var needleRegExp = new RegExp(needle.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), "i");
var result = needleRegExp.test(haystack);
if (result) {
}