Answers for "js if string contains space"

4

how to check if a string contains only spaces in javascript

let str = "    ";
if (!str.replace(/\s/g, "").length) {
  console.log("string only contains whitespace (ie. spaces, tabs or line breaks)");
}
Posted by: Guest on May-17-2021
0

javascript check if string ends with space

const str = "hello world ";
    const a = str.slice(-1);
    if (a == " ") {
        console.log("ends with space");

    }
Posted by: Guest on June-11-2021

Code answers related to "js if string contains space"

Code answers related to "Javascript"

Browse Popular Code Answers by Language