Nesne değerlerinin tekrarını saymak


( ! ) Notice: Undefined index: description in /home/prototurk.com/public_html/app/controller/demo.php on line 171
Call Stack
#TimeMemoryFunctionLocation
10.0001360464{main}( ).../index.php:0
20.0028442312require( '/home/prototurk.com/public_html/app/controller/demo.php' ).../index.php:101

Prototürk'e geri dön
let names = ['Tayfun', 'Mehmet', 'Ahmet', 'Gökhan', 'Tayfun']

let countedNames = names.reduce(function (allNames, name) { 
  if (name in allNames) {
    allNames[name]++
  } else {
    allNames[name] = 1
  }
  return allNames
}, {})

console.log(countedNames)
// { Tayfun: 2, Mehmet: 1, Ahmet: 1, 'Gökhan': 1 }