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

Is there a better way to structure post methods in Class Based Views -

What is happening when Matlab is starting a "parallel pool"? -

php - Cannot override Laravel Spark authentication with own implementation -