Currently, I am iterating through some JSON data (grouped tweets from Twitter) to tally the frequency of specific keywords (hashtags) in order to generate an organized list of common terms.
this (19)
that (9)
hat (3)
I have achieved this by initializing
var hashtags = [];
The process involves assigning a value of 1 for each new word encountered for the first time:
hashtags[new_tag] = 1;
For subsequent occurrences of the same word, I simply increment the count:
hashtags[hashtag]+=1;
This approach results in a straightforward data structure with words and their respective frequencies. To extract the necessary information, I utilize:
$.each(hashtags, function(i, val){
console.log(i+ " - "+ val);
})
Upon reflection, I realize it would be beneficial to also pinpoint the clusters in which these words are located. Therefore, I believe I should incorporate a list (array) within my "hashtags" object.
Essentially, I aim to construct a JSON format resembling:
hashtags: {"this": 19, clusters: [1,3,8]}, {"that": 9, clusters: [1,2]}
How can I seamlessly integrate arrays into the hashtags object?