I want to display similar JSON data in one row.
I'm trying to compare array index with keys index and store in new array
Expected result
this is my code
var array = [{ "english 1": "1", "english 2": "2", "hindi 1": "1", "hindi 2": "2", "gujarati 1": "1", "gujarati 2": "2", "marathi 1": "1", "marathi 2": "2" }]
keys = ['english', 'hindi', 'gujarati', 'marathi'],
grouped = {};
$.each(array, function (i, v) {
$.each(keys,function (ii, vv) {
var o = {};
o[vv] = v[vv];
grouped[vv] = grouped[vv] || [];
grouped[vv].push(o);
});
});
document.write('<pre>' + JSON.stringify(grouped, 0, 4) + '</pre>');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="tableData" class="table">
<thead>
<tr>
<th>Language</th>
<th>col 1</th>
<th>col 2</th>
</tr>
</thead>
<tbody id="showData">
</tbody>
</table>
