How to check whether a string contains a substring in JavaScript?

What is a reasonable way to check for the presence of a substring in a string in javascript?

Asked on October 27, 2018 in Javascript.
Add Comment


  • 1 Answer(s)

    There is a string.includes in ES6:

    “potato”.includes(“to”); = true

    However, it is to be noted that you may need to load es6-shim or similar to get this working on older browsers with the command:

    require(‘es6-shim’)

    Answered on October 27, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.