inbuilt function to copy array code example

Example 1: js add function to array

//create an new function that can be used by any array
Array.prototype.second = function() {
  return this[1];
};

var myArray = ["item1","item2","item3"];
console.log(myArray.second());//returns 'item2'

Example 2: graal.js pass javascript array to java function

Context context = Context.newBuilder("js").build();
Value result = context.eval("js", "var list=[1,2,'foo',true]; list;");
if (result.hasArrayElements()) {
    for (int i=0;i<result.getArraySize();i++) {
        System.out.println(result.getArrayElement(i));
    }
}