I would like to know if there is a native javascript code that does the same thing as this:
function f(array,value){ var n = 0; for(i = 0; i < arr
You can also use forEach
let countObj = {}; let arr = [1,2,3,1,2,3,4]; let countFunc = keys => { countObj[keys] = ++countObj[keys] || 1; } arr.forEach(countFunc); // {1: 2, 2: 2, 3: 2, 4: 1}