re: How to by using AJAX&Jquery to loop through a given Rest point (API)? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Hi Andy, yes the data comes back as JSON and it's an object of objects from which I need just a part of it not all the data.
 

You should be able to access that data and set it as a variable then. Here is an example:

// assuming you have an object structured like this:

{
  people: [ { name: 'Andy' }, { name: 'Deni'} ],
  someThing: {},
  someThingElse: {},
}

// you can do this:

let people = []
fetch('/api/subscribers')
  .then(response => response.json())
  .then(json => {
    people = json.people
  })

people.map(() => {
// do something with the array
})

It's up to you whether or not you want to store the entire data returned, which might make it easier for you in the long run:

let data = null
let people = []
fetch('/api/subscribers')
  .then(response => response.json())
  .then(json => {
    data = json
  })

// data is now available to be used
data.whatever()
code of conduct - report abuse