+ 1

Write a code to count the spaces in a string

I.e if I write "my name is" then result should be 2

22nd Nov 2017, 11:35 AM
Anand Yuvraj
Anand Yuvraj - avatar
2 Antworten
+ 4
var str= "my name is"; var a = str.match(/\s/g).length; alert(a);
22nd Nov 2017, 3:02 PM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 3
var str = 'my name is'; str.split(' ').length-1; // output 2
22nd Nov 2017, 11:42 AM
Calviղ
Calviղ - avatar