Hi, I am researching of subreddits to make my next product. I want to get an overview of how I sort subreddits.
This will use vanilla JS.
Copy the json data to your html code like this (and don't forget to parse it)
<script>
let json_subreddits = JSON.parse(`//the copy pasted json data`)
</script>
But the problem is our data is an object, and not an array.
To convert it, we need to iterate the object
let json_subreddits = JSON.parse(`the copy pasted json data`);
let sortable = [];
for (let subreddits in json_subreddits) {
sortable.push([subreddits, json[subreddits]]);
}
now we have an array
let json_subreddits = JSON.parse(`the copy pasted json data`);
let sortable = [];
for (let subreddits in json_subreddits) {
sortable.push([subreddits, json[subreddits]]);
}
sortable.sort(function(a, b) {
return b[1] - a[1];
// this will return from big to small. to inverse it, just switch the a and b
// return a[1] - b[1];
});
And you can view subreddits in your console. Enough to give you which subreddits are popular and which are least popular.
If you like this, you can follow my journey live on Twitter https://twitter.com/RicardoSawir
or follow me on IndieHacker here.