<head>
<style>
#arr,#now{
display: flex
}
</style>
</head>
<body>
<div id="arr">
</div>
<div id="now">
</div>
</body>
<script type="text/javascript">
// 显示模版
var model =
[
{view: "aa", value: [22,33]},
{view: "bb", value: [41,35]},
{view: "cc", value: [21,78,89]}
]
// 原始数据
var arr = [22,21,33,41,35,78,89,92]
printf("原始数据: ", "div", "#arr")
// 新的显示
var now = []
printf("显示结果: ", "div", "#now")
for(var i=0 i<arr.length i++)
{
var view = arr[i]
var views = model.filter(function(one){
var values = one.value.filter(function(two){
return two == arr[i]
})
return values.length>0
})
if(views.length>0) view = views[0].view
now.push(view)
var old = arr[i]
if(i<arr.length-1) old+=", "
printf(old, "div", "#arr")
var show = view
if(i<arr.length-1) show+=", "
printf(show, "div", "#now")
}
// 统计次数
var list = []
now.forEach(function(one){
var exist = list.filter(function(item){
return item.value == one
})
if(exist.length>0) exist[0].count++
else list.push({value:one,count:1})
})
// 打印结果
printf("出现次数: ")
list.forEach(function(one){
printf(one.value + ": " + one.count + "次")
})
function printf(val, tag, sel)
{
if(!tag) tag = "div"
var div = document.createElement(tag)
div.innerText = val
var e = document.querySelector(sel)
if(!e) e = document.body
e.appendChild(div)
}
</script>
</html>
上代码,有问题追问哈。
好的,我可以帮助您计算出js5条数据没行3条数据的行数。首先,我们需要知道js5条数据每行有多少个数据。假设每行有5个数据,那么js5条数据每行3条数据的行数就是:5/3=1.67,即有1.67行。如果每行有6个数据,那么js5条数据每行3条数据的行数就是:6/3=2,即有2行。因此,js5条数据每行3条数据的行数取决于每行有多少个数据。