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 -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -