2 回答
TA贡献1900条经验 获得超5个赞
使用Object.entries()和forEach()迭代对象的属性。
var student = [
{name:"alan",title:"al",platform:"test1",orderNumber:1 },
{name:"frank",title:"fr", platform:"test2",orderNumber:1},
{name:"bryan",title:"br", platform:"test3",orderNumber:1}
];
student.forEach(item => {
Object.entries(item).forEach(([key, value]) => {
console.log(key + ": " + value);
});
});
TA贡献1799条经验 获得超8个赞
这是一个实时链接https://dotnetfiddle.net/aQJP3W
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index18</title>
<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(function () {
$("#theButton").click(function () {
var student = [
{ name: "alan", title: "al", platform: "test1", orderNumber: 1 },
{ name: "frank", title: "fr", platform: "test2", orderNumber: 1 },
{ name: "bryan", title: "br", platform: "test3", orderNumber: 1 }
];
$.each(student, function (index, value) {
alert(value.name + "-" + value.title + "-" + value.platform + "-" + value.orderNumber);
});
})
})
</script>
</head>
<body>
<div>
<input type="button" value="Go" id="theButton" />
</div>
</body>
</html>
添加回答
举报