简体   繁体   中英

How do i get the total count of data objects in this API response

Im trying to write a code that retrieves data from a db and verifies if its matches the data that is synced in an online tool For that i need to know the number of ROWS created in the db table for comparison. A table is created for each entry and it goes something like this:

type: list
data: [ 
       {count 1},
       {count 2},
       {count 3}
       ]

now i need to get the number of "counts" in this object (which is 3 in this example). Some API's have a total_count tag which is helpul in getting me my info. but others dont. Anyway i can get that number?

If your Response is allways in an Array use Array.length

let apiRes = {data: [1,2,3]};
console.log(apiRes.data.length);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM