I play with the creation of a calculator for matrices. I see that it would be convenient to use objects, since each element of the matrix can be assigned its own name (in our case, this is a property of the object), and then these names are used to perform a set of very voluminous arithmetic operations.
However, I can’t get the value of the object properties:
var m1 = { x11: 1, x12: 2, x13: 3, x21: 4, x22: 5, x23: 6, x31: 7, x32: 8, x33: 9 } move to table:
<table id="matrix1"> <tr id="matrix1_tr1"> <td id="matrix1_td1"></td> <td id="matrix1_td2"></td> <td id="matrix1_td3"></td> </tr> <tr id="tr2"> <td id="matrix1_td4"></td> <td id="matrix1_td5"></td> <td id="matrix1_td6"></td> </tr> <tr id="tr2"> <td id="matrix1_td7"></td> <td id="matrix1_td8"></td> <td id="matrix1_td9"></td> </tr> </table> I have no problems filling the table through an array. There are also no problems with filling both arrays and objects with random numbers.
I also tried to fill the array (not yet the table, the markup of which is higher, but the array for training):
using the search properties for..in. But at the output the array goes empty.
using the for loop. And in this case, the array is filled, but with values undefined.
The question can be formulated as follows: how can I transfer the values from the object m1 to the table # matrix1 ? For example, in our case, the cell with the identifier # matrix1_td4 will have the value 4, and the cell with the identifier # matrix1_td9 will have the value 9.