2

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.

Galdiator
  • 117
  • 4
  • 14

2 Answers2

10

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.

erictgrubaugh
  • 8,519
  • 1
  • 20
  • 28
  • you provide far better solutions then netsuite gold support. both the things you mentioned worked. Thanks – Galdiator Dec 05 '16 at 15:56
  • I am very curious what they told you to do instead. – erictgrubaugh Dec 05 '16 at 22:56
  • 1
    They told: This is not part of Netsuite support since the solution you want is related to javascript. I told them that I am just giving you the example of what I want but they told there is no solution to such problem. – Galdiator Dec 06 '16 at 07:32
7

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;
Adolfo Garza
  • 2,966
  • 12
  • 15