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 :: math format comma separated in javascript 
Javascript :: jquery change value of input 
Javascript :: change word in string javascript 
Javascript :: get class count in jquery 
Javascript :: iso date javascript 
Javascript :: puppeteer stealth 
Javascript :: react-native resource android:attr/lStar not found in Android 
Javascript :: linking in react native 
Javascript :: props reactjs link 
Javascript :: how to read a json file in node js 
Javascript :: how to find factorial of a number using Recursion in javascript 
Javascript :: js email regex 
Javascript :: delete item from list javascript 
Javascript :: JavaScript - How to get the extension of a filename 
Javascript :: angular timestamp 
Javascript :: javascript get file extension from string 
Javascript :: javascript print out 
Javascript :: javascript get text between two strings 
Javascript :: how to take a input video on browser using javascript and play it 
Javascript :: how to change css with js 
Javascript :: jquery clear form values 
Javascript :: loop through object js 
Javascript :: iframe player youtube onfinish event 
Javascript :: date of birth validation for 18 years javascript 
Javascript :: javascript get second last element in array 
Javascript :: next router push state 
Javascript :: js check if date is future 
Javascript :: get last in array javascript 
Javascript :: how to add a shadow react native 
Javascript :: file input change event not firing angular 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =