mardi 21 juin 2022

Generate array of objects with unique value

Currently this code generate array with 10 objects with value number and display.The number is random from 0 to 9 so there can be duplicates. Is there a way, where i can get unique(all the objects having different number value ) number only?

const newArray = Array(10)
        .fill()
        .map(() => {
          return { number: Math.floor(Math.random() * 10), display: false };
        });



Aucun commentaire:

Enregistrer un commentaire