View Single Post
  #1646  
Old 16.01.2021, 10:52
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Quote:
Originally Posted by SMS View Post
What's a graceful way to check whether a string is contained in another string? Both strings are variables, so it can't be a hardcoded regex pattern.
You can use String/RegExp Object methods:
Code:
str1.indexOf(str2) > -1; // boolean
new RegExp(str2).test(str1) // boolean
Quote:
Originally Posted by SMS View Post
Usually JavaScript offers string1.includes(string2), or the older string1.contains(string2), but neither work.

In general, what JavaScript version does the Event Scripter use?
JD uses Rhino/ES5 version. ES6 methods like 'includes' are not supported.

You can define your own prototype:
Code:
String.prototype.includes = function(str2) {
    return this.indexOf(str2) > -1;
}

//Usage
var result = "str1".includes("str2"); // boolean
Quote:
Originally Posted by SMS View Post
And how do I find out what methods are available for a certain object or class? string1.getOwnPropertyNames() doesn't work.
Code:
Object.getOwnPropertyNames(String);
Quote:
Originally Posted by SMS View Post
@mgpai: Thanks for the YouTube script, I'll try it!
You're welcome.
Reply With Quote