How To Get All Unique Elements From An Array Using jQuery Function

AuthorSumit Dey Sarkar

Pubish Date23 Aug 2022

categoryJQuery

In this tutorial we will learn how to get all unique elements from an array using jQuery function.

Basically here we will learn how to get all the unique element from array and if any duplicate element found then it can not show again.

let's see example - 

How to get all unique elements from an array using jQuery function

<!DOCTYPE html>
<html>

<head>
    <title>How to get all unique elements from an array using jQuery function</title>
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>

<body>

    <script>
        var sites = ["teknowize.com", "w3school.com", "tutorialpoint.com", "teknowize.com"];

        var uniqueWebSites = sites.filter(function (item, i, sites) {
            return i == sites.indexOf(item);
        });

        alert(uniqueWebSites);
    </script>

</body>

</html>

 

Output

jQuery

Comments 0

Leave a comment