Is there an equivalent php strpos() function in Javascript?

Asked

Viewed 547 times

0

I would like to know if there is a php strpos() error function in javascript on mainly for the Node.js environment and would like to know how to use it.

1 answer

1


Trelhac, the closest function to PHP strpos in javascript is the index, where it returns an integer relative to the position of the searched string:

let valor = "Teste";

//Vai encontrar o valor
console.log(valor.indexOf("Tes"));

//Não vai encontrar o valor
console.log(valor.indexOf("tes"));

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf


In case you want to check only the contained, it is worth taking a read also on the includes:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes

  • have how I use this in if?

  • Here is an example: https://repl.it/repls/ProudDescriptiveDiscussions

Browser other questions tagged

You are not signed in. Login or sign up in order to post.