I all, i want make table format using JSON data. I have JSON data like this
var jsondata = [
{
id: 1,
name: 'Mani',
subject: English,
Score: 88
},
{
id: 1,
name: 'Mani',
subject: Maths,
Score: 65
},
{
id: 2,
name: 'Ram',
subject: English,
Score: 75
},
{
id: 3,
name: 'Kumar',
subject: English,
Score: 15
},
{
id: 3,
name: 'Kumar',
subject: science,
Score: 88
}];
In this data i would like to change like this format. I am not able to attached screenshot images so please check this below output code. same like output only i require using javascript.
<table border='1'>
<tr>
<th>
ID
</th>
<th>
Name
</th>
<th>
English
</th>
<th>
Maths
</th>
<th>
science
</th>
</tr>
<tr>
<td>
1
</td>
<td>
Mani
</td>
<td>
88
</td>
<td>
65
</td>
<td>
-
</td>
</tr>
<tr>
<td>
2
</td>
<td>
Ram
</td>
<td>
75
</td>
<td>
-
</td>
<td>
-
</td>
</tr>
<tr>
<td>
3
</td>
<td>
Kumar
</td>
<td>
18
</td>
<td>
-
</td>
<td>
88
</td>
</tr>
</table>
var jsondata = [
{
id: 1,
name: 'Mani',
subject: 'English',
Score: 88
},
{
id: 1,
name: 'Mani',
subject: 'Maths',
Score: 65
},
{
id: 2,
name: 'Ram',
subject: 'English',
Score: 75
},
{
id: 3,
name: 'Kumar',
subject: 'English',
Score: 15
},
{
id: 3,
name: 'Kumar',
subject: 'science',
Score: 88
}
]
var obj = jsondata;
var category = [];
var callid = [];
//alert("hai");
for (var i = 0; i < Object.keys(obj).length; i++) {
callid.push(obj[i]['subject']);
category.push(obj[i]['subject']);
}
var uniquecategory = uniquerResult(category);
var uniquecallid = uniquerResult(callid);
console.log(uniquecallid);
function uniquerResult(obj) {
var unique = [];
$.each(obj, function (i,ei) {
if ($.inArray(ei, unique) === -1) unique.push(ei);
})
return unique;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>