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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -