JavaScript, how to find characters in a string

How to find characters in a string using JavaScript?

How to find characters in a string using JavaScript?

You have an easy way.

Every string has oneincludes()A method that accepts one (or more) characters.

The method returnstrueIf the string contains characters, andfalseif not:

'a nice string'.includes('a') //true
'a nice string'.includes('b') //false

However, if you need to find the exact position of the letter in the string, you need to useindexOf()method:

'a nice string'.indexOf('a') //0
'a nice string'.indexOf('c') //4

If multiple events occur, this method returns to the position of the first event found from the left.

Download mine for freeJavaScript beginner's manual


More js tutorials: