How do I check if a string contains a different substring?

Asked 2 years ago, Updated 2 years ago, 37 views

How do I check if a string contains another string in JavaScript? Normally, I would use the String.contains() method, but I don't think I can. What can I do?

javascript string

2022-09-22 08:30

1 Answers

String.prototype.indexOf returns the position of the string. Returns -1 if the string is not included.

var string = "foo",
    substring = "oo";
console.log(string.indexOf(substring) > -1);


2022-09-22 08:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.