Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
var array = ['box','box','line','time','box']
例如:盒子重复了几次
干得好:
var array = ['box','box','line','time','box'], map = {}, key; array.forEach(function(item) { if (map[item] === undefined) { map[item] = 1; } else { map[item]++; } }); for (key in map) { console.log(" key:", key, " repeated:", map[key]); }