Last active
September 11, 2018 16:52
-
-
Save rafagarcia/89e3edbe92715e45cc6d6789afc2d298 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/jumexok
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cars = ['BMW','Benz', 'Benz', 'Tesla', 'BMW', 'Toyota']; | |
var carsObj = cars.reduce(function (obj, name) { | |
obj[name] = obj[name] ? ++obj[name] : 1; | |
return obj; | |
}, {}); | |
console.log(carsObj); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment