【发布时间】:2020-12-04 23:23:42
【问题描述】:
我的 for 代码只为最后一个数组项运行第二行代码。我怎样才能解决这个问题?使用地图是正确的方法吗?
$(document).ready(function () {
var data = [{test: "1!", test1: "2!", test2: "3!"}];
console.log(data);
data.map(function(item) {
for (var key in item)
console.log (key+": "+item[key]);
console.log ("this will only show on the last item - "+key+": "+item[key]);
}).join();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
【问题讨论】:
-
你想做什么?
标签: javascript jquery arrays for-loop