I am new to coding, so I would like to know how I can count words of an website with javascript. Should I use .innerText
and a for
loop?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
May be it can help you:
This will do the trick for you if the language on the site uses spaces to separate words.
Proof it works: http://codepen.io/nicholasabrams/pen/rVJPOx
This is how I would count the number of words as you type:
JSFiddle code here
Split on regular expression
/\W+/
(\W
matches anything that is not a latin letter or arabic number or an underscore) :More details on regexp can by found on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp