Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get distinct values from array of arrays

const arrOfObjs = [
    {
      name: 'someName',
      tags: [
        'sci-fi',
        'strategy',
        'sandbox',
      ]
    },
    {
      name: 'someOtherName',
      tags: [ 
        'sci-fi', 
        'mining', 
        'woodcutting', 
        'sandbox'
      ]
    }
  ];

let uniqueTags = [...new Set(arrOfObj.map(obj => obj.tags).flat(1))];

// ['sci-fi', 'strategy', 'sandbox', 'mining', 'woodcutting']
Comment

js get distinct values from array

var myArray = ['a', 1, 'a', 2, '1'];

let unique = [...new Set(myArray)];

console.log(unique); // unique is ['a', 1, 2, '1']
Comment

javascript get distinct values from array

const categories = ['General', 'Exotic', 'Extreme', 'Extreme', 'General' ,'Water', 'Extreme']
.filter((value, index, categoryArray) => categoryArray.indexOf(value) === index);

This will return an array that has the unique category names
['General', 'Exotic', 'Extreme', 'Water']

Comment

PREVIOUS NEXT
Code Example
Javascript :: convert map to object/JSON javascript 
Javascript :: how to generate color code from random number 
Javascript :: best javascript ide 
Javascript :: load script defer 
Javascript :: cheerio get href text 
Javascript :: find in array react 
Javascript :: toggle css class in javascript 
Javascript :: js date format mm/dd/yyyy 
Javascript :: node eventemitter emit error 
Javascript :: object keys and values javascript 
Javascript :: Redirect replacement in react 
Javascript :: jQuery CSS Classes 
Javascript :: webpack set mode to development 
Javascript :: hide and show modal in jquery 
Javascript :: input length material Ui Design 
Javascript :: jquery remove attribute 
Javascript :: word count javascript 
Javascript :: swapping elements in an array 
Javascript :: javascript get list of files in directory 
Javascript :: d3.json() function 
Javascript :: speedtest-net node.js 
Javascript :: jquery json object 
Javascript :: regex contains string in end 
Javascript :: object iterate in javascript 
Javascript :: smooth scroll to target with offset 
Javascript :: bootstrap js, jQuery, popper cdn 
Javascript :: run nextjs in separate port 
Javascript :: mongodb import from json 
Javascript :: click button javascript 
Javascript :: es6 check if the object is empty 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =