it seems that the answer is floating somewhere on the surface, but I can’t figure it out for an hour ...

in general, there is ajax function that returns a set of objects (the number of objects is always different), each of which has an array with elements (the number of elements is also always different).

As a result, there are two objects A (i, j, k), B (o, t, p), the result should look like this:


io


it


ip


jo


jt


jp


ko


kt


kp


thanks in advance

  • "ajax function that returns a set ..." - hardly ajax function returns what you think. - Igor

1 answer 1

var A = { i: 1, j: 2, k: 3 }; var B = { o: 1, t: 2, p: 3 }; var table = document.getElementById("myTable"); for (var i in A) { for (var j in B) { var tr = document.createElement('tr'); var td = document.createElement('td'); td.innerHTML = A[i]; tr.appendChild(td); var td = document.createElement('td'); td.innerHTML = B[j]; tr.appendChild(td); table.appendChild(tr); } } 
 <body> <table id="myTable"> </table> </body> 

  • one
    What is the fundamental difference between arrays and objects in this case? - Grundy
  • @Grundy, the element of the array is easier to access (A [i]) - Komdosh
  • one
    the object is the same A[i] - Grundy
  • @Grundy, can I have some code? - Komdosh
  • one
    All the same, only instead of for , use for..in - Grundy