Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const words = ["react", "angular", "react", "react", "redux"];
- const initialObject = {};
- const word = words.reduce(
- (acc, word) => {
- if (!acc[word]) {
- acc[word] = 1;
- } else {
- acc[word]++;
- }
- return acc;
- },
- initialObject
- );
- console.log(word);
- //output
- initialObject { react: 3, angular: 1, redux: 1 };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement