How to remove duplicates from string

To remove duplicate from string values use below formula

<html>

<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script>
        $(document).ready(function() {
            $("#btn1").click(function() {
                var result = "Samsung|Galaxy;Apple|iPhone7;Samsung|Note;Apple|iPhone7";
                result = Array.from(new Set(result.split(';'))).toString();
                $("#test1").text(result);

            });

        });
    </script>
</head>

<body>
    <p id="test1">This is a paragraph.</p>    
    <button id="btn1">Check Duplicate Value </button>
</body>

</html>

INPUT STRING: Samsung|Galaxy;Apple|iPhone7;Samsung|Note;Apple|iPhone7
OUTPUT/ RESULT STRING: Samsung|Galaxy,Apple|iPhone7,Samsung|Note

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s