let arr = [1, 2, 3, 2, 3], obj = {}; for (let val of arr) { obj[val] = (obj[val] || 0) + 1; } console.log(obj);
Output should be:
(输出应为:)
obj = { 1: 1, 2: 2, 3: 3 }
2.1m questions
2.1m answers
60 comments
56.8k users