0

I'm trying to use https://github.com/jsonurl/jsonurl-js to achieve this. I've tried the following code but I keep getting the result of 23.

I would like to store all values of test in testJSON and access each individual item by its index.

const test = (1, 2, 3, 23);
const testJSON = JsonURL.parse(test);
console.log(testJSON[2])
<script src="https://cdn.jsdelivr.net/npm/@jsonurl/jsonurl@1.1.5" integrity="sha512-PgDMK2pu/5iHU+sUvfCWIKugVg2NLSN1jmQJyJKbQw1MZAMvrU7XX3fPv4FJXgGBxTCsDnjhMmlZK5pzgPndTQ==" crossorigin="anonymous"></script>
mplungjan
  • 155,085
  • 27
  • 166
  • 222
Jacob
  • 65
  • 4
  • 1
    `(1,2,3,23)` is not a value. It's not json, and not an url part either. It's an expression that evaluates to the same as `const test = 23;` You want a string to parse: `const test = "(1, 2, 3, 23)";` – Bergi Jan 08 '22 at 07:57
  • If you instead do `const test = [1,2,3,23];` then you do not need any other code – mplungjan Jan 08 '22 at 07:59
  • Have a look [here](https://stackoverflow.com/a/41215441/3132019) – Gerard Jan 08 '22 at 08:00
  • There is [no such thing as a JSON-'object'](https://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/) – KooiInc Jan 08 '22 at 08:14

0 Answers0