找出数组中的元素出现次数
var arr5 = ["c","a","x","a","x","a"]; var json = {}; for(var i=0;i<arr5.length;i++){ //判断数组中的元素,在json中是否存在属性值。 if(json[arr5[i]]){ json[arr5[i]] += 1; }else{ json[arr5[i]] = 1; } } console.log(json);
var arr5 = ["c","a","x","a","x","a"]; var json = {}; for(var i=0;i<arr5.length;i++){ //判断数组中的元素,在json中是否存在属性值。 if(json[arr5[i]]){ json[arr5[i]] += 1; }else{ json[arr5[i]] = 1; } } console.log(json);