Remove Duplicate Value or Words from array Using JavaScript
javascript remove duplicates from array |
In This lesson we will Learn How to Remove Duplicate Value or Words from array Using JavaScript.
You can Remove any Duplicate Value form a from using This Method.
create 3 files named are given Below.
1.index.html
2.script.js
3.style.css
javascript remove duplicates from array |
Now Copy The below Codes for Certain File.
<html> <head> <title>Remove Repeted Value from Array-JavaScript</title> <script type="text/javascript" src="script.js"></script> <link rel="stylesheet" href="style.css" type="text/css"/> </head> <body> <div class="form"> <h1>Remove Repeted Value from Array-JavaScript</h1> <form name ="txtchk"> <input type="text" title="Please Enter Some Dulicate Text with value" name="mytextarea" size="30" placeholder="Ex:anjan anjan you you"/><br/> <input type="button" value="Remove Duplicates" onclick="delrepeat(mytextarea)" /> </form> </div> </body> </html>
function delrepeat(mytextarea) { var temp=document.txtchk.mytextarea.value; var array2 = temp.split(" ") ; var array1= new Array; for(var i = 0; i < array2.length; i++) { var xx = true; var ArrayVal = array2[i]; for(var j = i+1; j < array2.length; j++) { if(array2[j] == ArrayVal) xx = false; }if(xx == true) array1.push(ArrayVal) } document.txtchk.mytextarea.value=array1; }
body{ background:lightgreen; } .form{ width:50%; background:#666699; height:20%; float:top; color:white; } input[type=text]{ padding:8px; width:60%; border: 1px solid #666699; border-radius:4px; } input[type=text]:focus{ border:2px solid green; } input[type=button]{ padding:5px; border-radius: 5px; background: #666633; color:white; }
You have Successfully Created JavaScript Duplicate or Repeated Value Remover Script.
Now run index.html file to get Result.
Thank you for Visit.
No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.