I am dealing with a JSON output that can have different types of data:
There may be an array of objects like this:
var data = { "EARNINGS": [ { "PAYMENT": "1923.08", "REPORTING_NAME": "Regular Salary", "CATEGORY_NAME": "Standard Earnings" }, { "PAYMENT": "0", "REPORTING_NAME" "Spot Bonus", "CATEGORY_NAME": "Supplemental Earnings" } ] }
Or just a single object like this:
var data = { "EARNINGS": { "PAYMENT": "1923.08", "REPORTING_NAME": "Regular Salary", "RUN": "1923.08", } };
I'm struggling with how to loop through the "EARNINGS" object. It's straightforward when it's an array of objects, but when it's a single object, I need to determine whether it's an array or not.