0

I want to support my application that it can receive different kinds of json in a format like: {"EXAMPLE": [ "example1","example2","example3","example4" ]}

The problem I have here is that EXAMPLE could be any name. What I want is only receiving the values: example1,example2,example3,example4 (like in a for loop or something) I tried

          for (var i = 0; i < res.body.length; i++) {
              console.log(res.body[i]);
          }

what it does is it prints litterly every character from the res (json data) How can I make it so it will only print example1,example2 etc without referring to the object names?

I am working in javascript by the way

Bcoded
  • 83
  • 10
  • 2
    `Object.values(yourobject)` returns an array of values. If the object has only one key, `Object.values(yourobject)[0]` – adiga Apr 08 '19 at 14:15
  • _“what it does is it prints litterly every character from the res (json data)”_ — have you tried parsing the JSON first? – Sebastian Simon Apr 08 '19 at 14:15
  • http://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json – Teemu Apr 08 '19 at 14:15
  • 1
    Possible duplicate of [Get the value of an object with an unknown single key in JS](https://stackoverflow.com/questions/32208902/get-the-value-of-an-object-with-an-unknown-single-key-in-js) and [best way to get the key of a key/value javascript object](https://stackoverflow.com/questions/6268679) – adiga Apr 08 '19 at 14:18
  • @adiga Ooooh, you're right. – T.J. Crowder Apr 08 '19 at 14:20
  • 1
    @Bcoded - I've moved my answer to [this dupetarget](https://stackoverflow.com/questions/32208902/get-the-value-of-an-object-with-an-unknown-single-key-in-js). – T.J. Crowder Apr 08 '19 at 14:21

0 Answers0