ES6 Javascript (React) code that maps and filters JSON data I have the following code in my React app that creates tags out of JSON data:

const files = Object.values(gist.files);
const tags = files.map((file) =&gt; {
    let tag = file.language ? file.language : 'Plain Text';
    return tag;
});
let unique = [...new Set(tags)]; 
const unique_tags = unique.map((tag) =&gt; {
    return &lt;Tag value={tag}/&gt;;
});


The code starts by creating an array out of the files' JSON object, next it maps through the files array and returns the value of the language key (Javascript, C, etc.) and if its not undefined, returns plaintext. After that, it filters so there are only unique tags. Finally, it maps through the unique tags and returns a React component.

As you can see, there are two maps and one filter. I feel like this could be done more efficiently.

The JSON is coming from the GitHub Gist API.
For example: https://api.github.com/gists/25c75fa76cf151568d12
You can use a for..of loop to avoid using .map() twice and Set

const files = Object.values(gist.files);
const unique_tags = []; 

for (let file of files) {
  let tag = file.language ? file.language : 'Plain Text';
  if (unique_tags.indexOf(&lt;Tag value={tag}/&gt;) === -1) {
    unique_tags = [...unique_tags, &lt;Tag value={tag}/&gt;]
  }
}