0

Good evening,
I'm facing a simple problem in JSON. I'm developping a smartwatch (Pebble) app which gets data from an API, which returns the following :

{
  "name": "toto",
  "count": 55,
  "results": {
    "collection1": [
      {
        "article": "Content number 1"
      },
      {
        "article": "Content number 2"
      },
      {
        "article": "Content number 3"
      }
    ]
  }
}

The problem is the following : is it possible to access only the latest "article" content from this JSON ? So in this case, it would be "Content number 3".
Here is what I've got so far, but it returns only the 1st element :

ajax({ url: 'MY_API_URL', type:'json' }, function(data){
  simply.vibe(); // Vibrate the watch
  var message = data.results.collection1[0].article;
simply.body(message); // display the message on the watch


Thanks a lot !

1

2 Answers 2

3

That would be:

data.results.collection1[data.results.collection1.length - 1].article
Sign up to request clarification or add additional context in comments.

Comments

1

data.results.collection1[data.results.collection1.length-1].article;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.