在netsuite中找到一个字符串,然后打印出来

Gal*_*tor 1 netsuite suitescript

在netsuite suitescript 1.0中,我想检查一个字符串是否有一组关键字.在javascript中有一个名为.includes的函数("Set_of_keywords_to_be_searched"); 我试过.include在netsuite但它给出错误.

例如:

var str = "Hello world, welcome to the javascript.";
var n = str.includes("world");     // this will return true
var n = str.includes("Apple");     // this will return false
Run Code Online (Sandbox Code Playgroud)

我想在netsuite中使用类似的功能.

eri*_*ugh 8

使用RegExptest方法.请参阅MDN参考

会看起来像

var pattern = /world/;
var n = pattern.test(str);
Run Code Online (Sandbox Code Playgroud)

String#includes仅在ES2015中添加.NetSuite正在运行Rhino 1.7 JS引擎,它不支持任何ES2015或更高版本的JS.


Ado*_*rza 6

我通常会选择搜索方法,它易于使用和可读.如果找到该单词,则此方法返回第一次出现的索引,如果找不到单词,则返回-1.

var hasWorld = str.search("world") !=-1;
Run Code Online (Sandbox Code Playgroud)