Use square brackets, not parentheses:
str[i] === " "
Or charAt
:
str.charAt(i) === " "
You could also do it with .split()
:
return str.split(' ').length;
More Related Contents:
- How does this code call id with html?
- What’s the difference between event.stopPropagation and event.preventDefault?
- How to save an HTML5 Canvas as an image on a server?
- How can I unset a JavaScript variable?
- Is it possible to send a variable number of arguments to a JavaScript function?
- Cross browser JavaScript (not jQuery…) scroll to top animation
- How do I upload a file with the JS fetch API?
- How can I guarantee that my enums definition doesn’t change in JavaScript?
- How to create a dialog with “Ok” and “Cancel” options
- When do I use parentheses and when do I not?
- Handling errors in express async middleware
- Prevent form submission with enter key
- Server Side Calculation using Firebase
- Download Canvas as PNG in fabric.js giving network Error
- What events does an fire when its value is changed?
- What’s the difference between putting script in head and body?
- Binding vs Arrow-function (in JavaScript, or for react onClick)
- Calculate working days between two dates in Javascript excepts holidays
- Javascript: best Singleton pattern [duplicate]
- How to open specific tab of bootstrap nav tabs on click of a particuler link using jQuery?
- Can’t resolve module (not found) in React.js
- Highcharts percentage of total for simple bar chart
- (*SKIP)(*FAIL) workaround in JavaScript RegExp
- The collection nested inside firebase collection’s model doesn’t have add function
- JS checking deep object property existence [duplicate]
- How to create a custom input type?
- 307 Redirect when loading analytics.js in Chrome
- How to fix chrome-extension inline JavaScript invocation error?
- How can I capture an image via the user’s webcam using getUserMedia?
- does location of e.preventDefault() matter