What's wrong with javascript string search? -


why snippet not generate 6? , generates -1?

<!doctype html>  <html>  <body>    <script>      res =('{"name_^":"ali","age":34}'.search('_^'));      document.body.innerhtml = res ;    </script>  </body>  </html>

you're looking indexof function:

'{"name_^":"ali","age":34}'.indexof('_^') 

returns 6 (search uses regex, , ^ has special meaning in regex- -1 means string wasn't found)


Comments

Popular posts from this blog

angular - DownloadURL return null in below code -

python 2.7 - Given three nested dictionaries, sort the top two nested dictionaries from a value in the innermost dictionary? -