Ivan Ivan - 1 year ago 115
JSON Question

How to fix fetching JSON data on inside of loop with limit number?

There is something bothers me.
I'm trying to understand this output in console, take a look

loop and json data

listdata is a global variable.

I can use listdata.orders[x].id_order to return any numbers without errors.

Then I use for() to make a list and it gave me an error that doesn't make sense =/

EDIT: It needs to be limited as 9 items, not complete as data.length

Answer Source

Use this

listdata.orders.forEach(function (order) {

To limit the iteration to 9 orders.

Method 1:

listdata.orders.slice(0, 9).forEach(function (order) {

Method 2:

listdata.orders.some(function (order, index) {
    if (index > 9) {
        return true;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download