我试图检查一个灯具发布了多少次,我列出了所有团队的清单,然后列出了所有拥有灯具的团队。这是固定装置的清单。
(8) [Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1)]
0: ["Fulham v Arsenal"]
1: ["Crystal Palace v Southampton"]
2: ["Liverpool v Leeds United"]
3: ["West Ham United v Newcastle United"]
4: ["West Bromwich Albion v Leicester City"]
5: ["Tottenham v Everton"]
6: ["Sheffield United v Wolverhampton Wanderers"]
7: ["Brighton and Hove Albion v Chelsea"]
然后这是关于他们的帖子的人
0: ["Liverpool v Leeds United"]
1: ["Crystal Palace v Southampton"]
2: ["Crystal Palace v Southampton"]
所以我基本上想做一个最终的数组,像这样:
(8) [Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1)]
0: ["Fulham v Arsenal", 0]
1: ["Crystal Palace v Southampton", 2]
2: ["Liverpool v Leeds United", 1]
3: ["West Ham United v Newcastle United", 0]
4: ["West Bromwich Albion v Leicester City", 0]
5: ["Tottenham v Everton", 0]
6: ["Sheffield United v Wolverhampton Wanderers", 0]
7: ["Brighton and Hove Albion v Chelsea", 0]
我正在使用此代码制作Google条形图。这是我到目前为止创建的代码。
var fixposts = [];
var posts = [];
var postsc = [];
var finala = [];
var y = 0;
var z = 0;
function getOccurrence(array, value) {
var count = 0;
array.forEach((v) => (v === value && count++));
return count;
}
<c:forEach items="${fixtures}" var="fix" varStatus="count">
fixposts.push(['<c:out value="${fix.home.teamName} v ${fix.away.teamName}"/>']);
</c:forEach>
console.log(fixposts);
<c:forEach items="${posts}" var="post" varStatus="count">
posts.push(['<c:out value="${post.fixture.home.teamName} v ${post.fixture.away.teamName}"/>']);
</c:forEach>
console.log(posts);
fixposts数组是该周所有拥有固定装置的团队,而postpost是该周具有固定装置的团队以及有关它们的帖子。然后,我将如何将这两种方法结合在一起,以便可以将一个包含所有灯具的阵列组成一个数组,或者将其设置为0或创建多少个帖子?谢谢你。
您可以for-loop
用来遍历fixposts
&,posts
然后检查值是否匹配(如果是)增加count
值并存储在新数组中。
演示代码:
//this you will get from jsp code ..
var fixposts = [
["Fulham v Arsenal"],
["Crystal Palace v Southampton"],
["Liverpool v Leeds United"],
["West Ham United v Newcastle United"],
["West Bromwich Albion v Leicester City"],
["Tottenham v Everton"],
["Sheffield United v Wolverhampton Wanderers"],
["Brighton and Hove Albion v Chelsea"]
]
var posts = [
["Liverpool v Leeds United"],
["Crystal Palace v Southampton"],
["Crystal Palace v Southampton"]
]
var new_array = [];
//loop through fixpost array
for (var i = 0; i < fixposts.length; i++) {
var count = 0;
//use `0` because fixpost is array of arary so inner array is `0` index
for (var j = 0; j < posts.length; j++) {
//comapre
if (fixposts[i][0] == posts[j][0]) {
count++;
}
}
//store in new array
new_array.push([fixposts[i][0], count])
}
console.log(new_array)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句