I have javascript object with array as showing below
const object1 = {
"sublists": {
"item": [
{
"line": "1",
"amount": "1200.00",
"id": "227",
"item": "227",
"item_display": "5800520002800",
"quantity": "1"
}
] ,
"shipping": [
{
"line": "1",
"amount": "1200.00",
"id": "227",
"quantity": "1"
}
]
}
}
here is the code
jv = jsonData.sublists ;
function printValues(obj) {
for(var k in obj) {
// console.log(k+obj[k]);
if(obj[k] instanceof Object) {
printValues(obj[k]);
} else {
console.log(k+''+obj[k] );
};
}
};
printValues(jv );
with this code i can get the array properties and values but cant get the desired output as showing below
desired output
Array name :item, line: , 1
Array name :item ,amount : 1200
Array name :item, id : 227 and so son
and so on … the array properties can varry depending on the json ouput , im looking for a dynamic script in which i could access the array name and properties