Given a JSON object with arrays, I'm able to loop through and display each of the tags from each object, but there are duplicate tags in each. How can I loop through and check that a tag doesn't already exist, then push it onto the array? I've tried creating an empty array, looping through and pushing each item into a new array, but this doesn't seem to be working correctly. In the end, I should have an array of tags that I can display in a list, where there are no duplicate tags.
jQuery
$.each( this.data, function(key,value){
$.each( value.tags, function(i, j){
console.log("TAGS", j);
var array = [];
var items = array.push(j);
console.log("ITEMS ARRAY", array);
$("ul.tag-list").append("<li><span class='tag is-link'>" + j + "</span></li>");
});
});
JSON Object
[
{
"tags": ["melodrama", "romance", "time travel"]
},
{
"tags": [
"melodrama",
"historical",
"romance",
"war",
"fantasy",
"period drama",
"based on a novel"
]
},
{
"tags": [
"mystery",
"thriller",
"action",
"crime",
"comedy",
"feature film"
]
},
{
"tags": ["romantic comedy", "romance", "fantasy"],
},
{
"tags": ["romantic comedy", "romance", "comedy"],
},
{
"tags": ["romance", "comedy", "drama", "romantic comedy"]
},
{
"tags": ["romance", "medical"]
},
{
"tags": [
"romantic comedy",
"comedy",
"family relationships",
"Staff Favorites"
]
},
{
"tags": ["romantic comedy", "romance", "fantasy", "based on a manga"]
},
{
"tags": ["romance"]
}
]
Partial example of current results:
I need to only have each tag show once, for example (melodrama, romance, etc).