-2

I am parsing JSON data and property name is unknown. I am sharing my code please tell me how can i get all data with unknown property

datas.data.videoGroup.past after that please use a loop

$.each(datas.data.videoGroup.past.Algebra, function(i, v) {
    var hash5 = v.id;
    var link = hash5;
    var tblRows = "<tr>" + "<td>" + v.title + "</td>" + "<td>" + 2 + '  ₹' + "</td>" + "<td><a target='_blank' href='" + link + "'>" + "WATCH/DOWNLOAD" + "</a></td>" + "</tr>";
    $(tblRows).appendTo("#userdata");
});
$.each(datas.data.videoGroup.past["Number System"], function(i, v) {

I put Number System and Algebra manually but i can't do it with each subject and for each teacher.

uminder
  • 23,831
  • 5
  • 37
  • 72
Ravi
  • 11
  • 2
  • Does this answer your question? [How to iterate over a JavaScript object?](https://stackoverflow.com/questions/14379274/how-to-iterate-over-a-javascript-object) – Matt U Dec 17 '19 at 04:58
  • please edit your answer in my question – Ravi Dec 17 '19 at 04:59

1 Answers1

0

Either iterating over the properties using for...in loop or getting the list of all the known keys on the object using the Object.keys() method; which returns an array containing all the keys which can be mapped over.

const obj = {
  a: 'hello',
  b: 'world',
  c: 'test',
};


for (const prop in obj) {
  console.log(`${prop}: ${obj[prop]}`);
}

// "a: 1"
// "b: 2"
// "c: 3"


console.log(Object.keys(obj));
// ["a", "b", "c"]
#

Something like -

for( const prop in datas.data.videoGroup.past) {
    $.each(datas.data.videoGroup.past[prop], function(i, v) {
    var hash5 = v.id;
    var link = hash5;
    var tblRows = "<tr>" + "<td>" + v.title + "</td>" + "<td>" + 2 + '  ₹' + "</td>" + "<td><a target='_blank' href='" + link + "'>" + "WATCH/DOWNLOAD" + "</a></td>" + "</tr>";
    $(tblRows).appendTo("#userdata");
});
}
Spandan
  • 221
  • 1
  • 4