I have a string "John Doe's iPhone6"
Visually, I know that it contains 2 spaces.
How do I count spaces in a string in javascript ?
var input = this.value;
// console.log(input.count(' '));
Try this
var my_string = "John Doe's iPhone6";
var spaceCount = (my_string.split(" ").length - 1);
console.log(spaceCount)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With