ex 1:
data =`{"serialNo": "1","items":{"item":[{"RECORDNO": "2", "amount" = 40},{"RECORDNO": "3","amount" = 40}]},}`
ex 2:
data=`{"serialNo": "2","items":{"item":{"RECORDNO": "4841","amount" = 40}}}`
The above is an example of a JSON value returned from an API call. The type is a little inconsistent as seen above. If the item has only one record, the json type is an object. If the item has multiple records the json type is an array. I am interested in extracting the item and process it.
const vals = [data.items.item][0];
vals.forEach(val => {
// do something
});
The code above works well for ex 1 but fails for ex2 as it's not of the type array.
What would be an easiest way to extract the item as an array to process easily.