DaMan56100
DaMan56100

Reputation: 65

JS Error: <parameter>.contains is not a function, not sure why

I've been writing some JavaScript code, and introduced this small function:

function decodeLink(thelink) {
    console.log(typeof(thelink)); // Reports 'string'

    if (thelink.contains("something")) {
        // Cool condition
    }
}

However, if I was to call decodeLink("hello");, I get this error:

TypeError: thelink.contains is not a function

Note that I'm using node.js and discord.js, however commenting the imports out yields no results.

I've been using to the strongly typed C# style of programming, this weak typing is quite new to me. I'm sure I've missed something important (such as some explicit way to tell the program it's dealing with a string), but no search lead me closer as to what...

Upvotes: 2

Views: 2286

Answers (1)

ellipsis
ellipsis

Reputation: 12152

The method you need is called includes not contains

function decodeLink(thelink) {
    console.log(typeof(thelink)); // Reports 'string'

    if (thelink.includes("something")) {
        // Cool condition
    }
}

Upvotes: 2

Related Questions