Archi Forum

Archi Plug-ins => jArchi => Topic started by: kkosienski on December 21, 2022, 14:36:21 PM

Title: JScript Question on includes() statement
Post by: kkosienski on December 21, 2022, 14:36:21 PM
Im trying to use the includes() statement in an if statement to test for a string pattern in an element name. Any suggestions on how I can accomplish this in jScript?  Here is a first attempt I made but got an error.

$("element").each(function(c) {

  var elementname = c.name;
 
  if(elementname.includes("copy")){
 
     console.log(elementname);
  }
});
Title: Re: JScript Question on includes() statement
Post by: kkosienski on December 21, 2022, 17:20:14 PM
I did not see a documented way to use regex or other pattern match within a name selector. I would have tried to solve for it that way.
Title: Re: JScript Question on includes() statement
Post by: Phil Beauvoir on December 21, 2022, 17:25:44 PM
I can't see anything wrong there. What is the error message?
Title: Re: JScript Question on includes() statement
Post by: kkosienski on December 21, 2022, 18:24:44 PM
I am getting the following error.

Script Error at: javax.script.ScriptException, javax.script.ScriptException: TypeError: elementname.includes is not a function in file:/C:/Users/mm45582/AppData/Roaming/Archi4/scripts/examples/Delete%20Unused%20Elements.ajs at line number 18
Title: Re: JScript Question on includes() statement
Post by: Phil Beauvoir on December 21, 2022, 18:26:48 PM
Please use the "GraalVM" JavaScript engine in the "Scripting" Preferences.
Title: Re: JScript Question on includes() statement
Post by: kkosienski on December 21, 2022, 20:36:50 PM
I am only seeing Nashorn ES5 & ES6 as options.
Title: Re: JScript Question on includes() statement
Post by: Phil Beauvoir on December 21, 2022, 20:45:49 PM
What version of jArchi are you using?
Title: Re: JScript Question on includes() statement
Post by: kkosienski on December 21, 2022, 20:50:54 PM
Archi 4.9.1 and Jscript plugin version 0.7.2.202002281033
Title: Re: JScript Question on includes() statement
Post by: Phil Beauvoir on December 21, 2022, 20:54:46 PM
The latest version of jArchi is 1.3.1 running under Archi 4.10 available as a binary for supporters of Archi (or build it yourself from source).

BTW, it's jArchi not "Jscript".
Title: Re: JScript Question on includes() statement
Post by: kkosienski on December 21, 2022, 21:00:24 PM
Thanks for your help on this.