-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunique_elements_arr.html
More file actions
42 lines (36 loc) · 1.23 KB
/
Copy pathunique_elements_arr.html
File metadata and controls
42 lines (36 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var arr =["abc","kumar","xyz","pqr","sanjay","abc","pqr","mno","karan","subhas","sanjay","kumar"];
// document.write(" old Array :- "+ arr +"<br>");
// var unique = [];
// for(let i = 0 ;i<arr.length; i++)
// {
// if(unique.indexOf(arr[i]) == -1)
// {
// unique.push(arr[i]);
// }
// }
// document.write(" new Array :- "+ unique);
// -->
document.write(" duplicate Array :- "+ arr +"<br><br>");
for (let i=0 ; i< arr.length;i++)
{
for (let j= i+1; j<arr.length;j++)
{
if(arr[i]==arr[j])
{
arr.splice(j,1);// we used splice( indexOnWhichOperation_perform , no. of delete ele , elements to be enserted ,elements to be enserted,.,.,.,. ) method here
}
}
}
document.write(" unique Array :- "+ arr +"<br>");
</Script>
</body>
</html>