Array unique values

1004 0 0 0

Last Updated : 2024-04-27 16:42:15

In order to get the unique values from an array , there are many ways, through using Set , or filter() method on array values or other methods.


  1. Using Sets
    var myArray = ['a', 1, 'a', 2, '1'];
    let unique = [...new Set(myArray)];
    // unique is ['a', 1, 2, '1']

    //---------------------------------
    var uniqueItems = Array.from(new Set(myArray ))?

    Mohammed Anwar

    Mohammed Anwar

    Experienced technical lead PHP, MySQL and Laravel Developer for 15+ years, with proven ability to develop and create high-quality and optimized web applications. Great ability to build and optimize database design, schema and queries. Versed programing trainer and instructor delivering web courses and helping others to get into the field in a timely manner. Fast and eager learner for new technologies .