var s= [{"id":"1","deleted":"0","data":[{"title":"Business Unit","value":"bus 1"},{"title":"Company ID","value":"comp 1"},{"title":"Parent ID","value":"parent 1"},{"title":"NPI","value":"npi 1"}]}];
i want to display in a table?
var s= [{"id":"1","deleted":"0","data":[{"title":"Business Unit","value":"bus 1"},{"title":"Company ID","value":"comp 1"},{"title":"Parent ID","value":"parent 1"},{"title":"NPI","value":"npi 1"}]}];
i want to display in a table?
Your variable s
is an array which contains one single element which is an object.
var s = [{}]
I see you have the "data"
key inside the single object, whose value is an array:
"data": [{
"title": "Business Unit",
"value": "bus 1"
}, {
"title": "Company ID",
"value": "comp 1"
}, {
"title": "Parent ID",
"value": "parent 1"
}, {
"title": "NPI",
"value": "npi 1"
}]
To iterate over arrays (this is what you are asking for in your comment), you can use:
i.e.
for (const element of s[0]['data']) {
console.log('title', element.title); // will output 'Business Unit' for first element
console.log('value', element.value); // will output 'bus 1' for first element
}
i.e.
s.forEach(element => console.log(element));
// will output the single object contained in var s.
// You can access each key with dot or bracket notation (element[id]) or (element.id)
To iterate over an object keys and values, you can use Object.entries() method. i.e.
for (const [key, value] of Object.entries(s[0])) {
console.log(`${key}: ${value}`);
// First line will be: id: 1
}
I also advice you to check MDN documentation for any doubt regarding JavaScript.