-1

In my Javascript code, I have an if condition in my method that check if the parameters is an Array:

    if (Array.isArray(value)) {
        return true;
    }

  return null;

The value is a JSONArray like this:

[{title: "james", author: "potter"}]

But always return null.

Is a JSONArray from Java, I am using Nashorn at Java 8 that allows you tu call Javascript methods from Java code.

What type should I use to return true?

gtx911
  • 1,189
  • 4
  • 25
  • 46
  • 1
    Can't reproduce. `Array.isArray([{title: "james", author: "potter"}]) === true` – CertainPerformance Feb 20 '19 at 11:15
  • No it does not. What is `value` exactly? We need a [mcve]! – Jonas Wilms Feb 20 '19 at 11:16
  • 1
    There is no such thing as a `JSONArray` in JavaScript. Either is JSON (i.e. a string) or an array. Read about [the difference between JSON and Object Literal Notation](https://stackoverflow.com/questions/2904131/what-is-the-difference-between-json-and-object-literal-notation). – str Feb 20 '19 at 11:19

1 Answers1

0

Try this if (Array.isArray (JSON.parse (value))) {return true;}