1

I've got a Json object named data. It has the following content:

{"query":{"pages":{"856":{"pageid":856,"ns":0,"title":"Mededelingen","revisions":[{"*":"* News item number one\n* News item number two"}]}}},"query-continue":{"revisions":{"rvstartid":12446}}}

How do I go about returning News item number one\n* News item number two?

I thought I would get that when using the following code:

console.log(data.query.pages.856.revisions.0);

However, this code returns errors.

SyntaxError: missing ) after argument list

Presumably because some of the object names are numbers. Also, I do not wish to refer to the object "name" 856 since this is dynamic.

The structure of the object will always have the same amount of sub-items. The names of the ID's can differ however.

Is there a way of always returning the inner message? No matter the given ID's? Inner message in my example being: News item number one\n* News item number two.

amarnath
  • 785
  • 3
  • 19
  • 23
timo
  • 2,119
  • 1
  • 24
  • 40

1 Answers1

4

This will give you what you want to return

var key = Object.keys(data.query.pages)[0] //return 856
data.query.pages[key].revisions[0]["*"]
Mritunjay
  • 25,338
  • 7
  • 55
  • 68