“JS obtém valores distintos da matriz” Respostas de código

JavaScript obtém valores únicos da matriz

const myArray = [1,2,3,1,5,8,1,2,9,4];
const unique = [...new Set(myArray)]; // [1, 2, 3, 5, 8, 9, 4]

const myString = ["a","b","c","a","d","b"];
const uniqueString = [...new Set(myString)]; //["a", "b", "c", "d"]
Batman

Array valores únicos javascript

const myArray = ['a', 1, 'a', 2, '1'];
const unique = [...new Set(myArray)]; // ['a', 1, 2, '1']
PandaNïrio

JavaScript obtém valores distintos da matriz

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']

McBurd

JS obtém valores distintos da matriz

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

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

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

Respostas semelhantes a “JS obtém valores distintos da matriz”

Perguntas semelhantes a “JS obtém valores distintos da matriz”

Mais respostas relacionadas para “JS obtém valores distintos da matriz” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código