JavaScript
- 6 ответов
- 0 вопросов
5
Вклад в тег
var products = [
{"id": "1", "name": "Имя1"},
{"id": "2", "name": "Имя2"},
{"id": "3", "name": "Имя3"}
];
var html = '<table>';
var cnt = 0;
for(var i in products) {
if(cnt == 0) {
html += '<tr>';
}
html += '<td>'+products[i]['id']+'</td>' + '<td>'+products[i]['name']+'</td>';
cnt++;
if(cnt == 2) {
cnt = 0;
html += '</tr>';
}
}
if(cnt != 0) {
html += '<td></td><td></td></tr>';
}
html +='</table>';
$val = array_map(function($a){ return "{".$a."}"; }, array_values($arr));