json格式

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script type="text/javascript">
var a = ['a','a','a','b','b','c','c','c','c','d','hha','niha'];
var s = '';
var json = {};
a.forEach(function(val,index){
if(s!=val){
s = val;
}
json[s]?json[s]++:(json[s]=1);
})
console.log(json)
</script>
</body>
</html>

posted on 2017-05-25 14:49  烟花丶瞬间  阅读(123)  评论(0编辑  收藏  举报

导航