js code to check if string has a space code example Example: javascript detect space in string if(str.indexOf(' ') >= 0){ console.log("contains spaces"); }