JavaScript Removing Duplicate From Arrays Example


Share:
Published By: Admin, Published On: Nov 11, 2021, Category: Javascript


Hello Friends,

Now let's see example of how to removing duplicate from array example. We will use how to removing duplicate from array in javascript. This is a short guide on removing duplicate from array. Let's get started with how to find removing duplicate from array in javascript.

Here i will give you many example how you can removing duplicate from array javascript.

Example : 1
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>JavaScript Removing Duplicate From Arrays Example - MyWebtuts.com</title>
    </head>
    <body>
        <h3>JavaScript Removing Duplicate From Arrays Example - MyWebtuts.com</h3>
        <script>  
            var subj = ["Laravel","Php","Laravel","JavaScript","Php"];  
            function filterDuplicates(new_subj){  
                return new_subj.filter((value,index) =>new_subj.indexOf(value)===index);  
            }  
            document.write(filterDuplicates(subj));  
        </script>  
    </body>
</html>
Output :
Laravel,Php,JavaScript
Example : 2
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>JavaScript Removing Duplicate From Arrays Example - MyWebtuts.com</title>
    </head>
    <body>
        <h3>JavaScript Removing Duplicate From Arrays Example - MyWebtuts.com</h3> 

        <script>  
            var array = ["Laravel","JavaScript","JQuery","Laravel","JQuery"];  
            
            function duplicates(subject){  
                let collect=[];  
                subject.forEach(value=>{  
                    if(!collect.includes(value))  
                    {  
                        collect.push(value)  
                    }  
                });  
                return collect;  
            }  
            document.write(duplicates(array));  
        </script>  
    </body>
</html>
Output :
Laravel,JavaScript,JQuery

It will help you...

Share: