I have a large array filled with various words, and I am aiming to create a new array that organizes each word along with the number of times it appears as properties within an object. Here is an example:
const arrayWithWords = [`word1`, `word2`, `word5`, `word1`, `word3`, `word6`, `word2`, `word3`, `word1`, `word5`]
// Desired output:
const newArray = [ {name: `word1`, amount: 3} {name: `word2`, amount: 2} {name: `word3`, amount: 2} {name: `word4`, amount: 0} {name: `word5`, amount: 2} {name: `word6`, amount:1}]
I've attempted to solve this using a for-loop, but I always seem to encounter roadblocks. Can you suggest a potential solution to tackle this issue?