I have a javascript file fun.js
function fun1(){
var arr =['This','is','from','js'];
return arr;
}
I want to get this array in java array so I used nashorn as-
try{
ScriptEngine engine= new ScriptEngineManager().getEngineByName("nashorn");
engine.eval(new FileReader("fun.js"));
Invocable invocable = (Invocable) engine;
Object obj = (Object)invocable.invokeFunction("fun1");
System.out.println(obj.toString());
}
catch(Exception e){
e.printStackTrace();
}
But I am getting this output- [object Array]
How can I get this output as java array?
eval()is one of the worst things you could ever do in any language.fun1