我正在尝试以表格形式迭代列表。以下列表应使用以下表格以表格形式呈现*ngFor:
输入/输出
let list = [
{
"key1": {
"subkey1": [
1,
2,
3,
1
],
"subkey2": [
3,
2,
3,
4
]
}
},
{
"key2": {
"subkey1": [
1
],
"subkey2": [
0
]
}
}
]
Run Code Online (Sandbox Code Playgroud)
表格格式(表格应以这种方式呈现):
Categories | subkey1 | subkey2
key1 | 1,2,3,1 | 3,2,3,4
key2 | 1 | 0
Run Code Online (Sandbox Code Playgroud)
我试过了但是错了:
我尝试在component.html中进行迭代的代码:
<table border="1">
<thead>
<tr>
<th>Categories</th>
<th *ngFor="let each of categoriesHeading"> {{each}} </th> // Array of subkeys
</tr>
</thead>
<tbody *ngFor="let each …Run Code Online (Sandbox Code Playgroud) I have heard that JavaScript does not support associative arrays. Is it true
I mean:
assocArray = [
{a: ""},
{b: ""},
{c: ""}
];
Run Code Online (Sandbox Code Playgroud)
how to get the keys of above assocArray?
I tried using:
for (each in assocArray) {}
Run Code Online (Sandbox Code Playgroud)
it gives: 0, 1, 2