JS determines the number of repetitions of an array

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>前端/NODEJS/HTML5 458633781</title>
		<script>
			//传入数组返回json
			function choseRepeat(arr) {
				//传入数组
				var ary = arr;
				var nary = ary;
				var count = 0;
				var jsonStr = {};
				for(var i = 0; i < ary.length; i++) {
					for(var j = 0; j < nary.length; j++) {
						if(ary[i] == nary[j]) {
							count += 1;
							jsonStr[ary[i]] = count;
						}
					}
					count = 0;
				}
				console.log("号码出现次数key为号码,val为次数:"+JSON.stringify(jsonStr));
				document.write("更多技术交流:前端/NODEJS/HTML5 458633781:["+arr+"]的结果为:"+JSON.stringify(jsonStr));
				return jsonStr;
			}
			choseRepeat([3,4,21,3,3,3]);
		</script>
	</head>
	<body>
	</body>
</html>

Determine the number of times the current incoming array elements appear. The key is the number, and the value is the number of times.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325475169&siteId=291194637