Find a string in netsuite, and print it

China☆狼群 提交于 2020-01-05 05:35:06

问题


In netsuite suitescript 1.0, I want to check whether a string has a set of keywords. In javascript there is function called as .includes("Set_of_keywords_to_be_searched"); I tried .includes in netsuite but its giving error.

Eg:

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

I want similar function in netsuite.


回答1:


Use a RegExp and the test method. See MDN Reference

Will look something like

var pattern = /world/;
var n = pattern.test(str);

String#includes was only added in ES2015. NetSuite is running the Rhino 1.7 JS engine, which does not support any ES2015 or later features of JS.




回答2:


I usually go for the search method, its easy to use and readable. If the word is found this method returns the index of the first occurrence and it will return -1 if it can't find the word(s).

var hasWorld = str.search("world") !=-1;


来源:https://stackoverflow.com/questions/40975611/find-a-string-in-netsuite-and-print-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!