Count occurrences of each item in JSON

Thanks, glad to hear this helped!

The way I approached this isn’t super specific to JavaScript. When seeing a logical problem I first try to break it down into smaller chunks. In this case, it was trying to understand what data pieces we need. And the first thing that came to my mind was a list of companies because we want to count something for each company. So I started like this:

  • The first chunk so to speak was to extract a list of companies from your example array consisting of objects. So for this I’d then find out how to extract specific values from an array of objects (that’s what .map() does here, transforming each value in an array on the fly - in this case from a nested object to a simple string).
  • The next step was then to remove duplicates, cause you typically want only one entry for each company. That’s something the Item Lists node could help with, but since I expected code to be required anyway I skipped using a separate node for this here and went with creating a unique_audiences array based on a Set (which is a storage for unique values) using the Spread syntax. At this stage I have my “unique company list”.

Now this might sound complex and like I have just learned these things at some point, but full disclosure, that’s not the case :wink: . So I typically search for the correct syntax or method when required (e.g. the first result for getting unique values from an array was this one, which lists some solutions). I’ve shared my go-to reference here, but any search engine of your choice will do the job as well.

So tl;dr I don’t have any great advice on learning JS unfortunately (it’s been quite a while since my college days and we focused on other languages back then). I just tried to transfer familiar concepts as good as possible (which worked out well so far).

I do however know that @BlueRabbit3 was thinking about working through a free JS course recently, maybe she already has some initial feedback and can share the course she was looking at?

2 Likes