Dr.Ajay Kashyap

Dr.Ajay Kashyap

  • NA
  • 521
  • 283.7k

javascript find duplicate Stringin array

Feb 8 2017 5:24 AM
javascript find duplicate string in array if there is duplication page not post but after show alert page is post ..so how to avoid 
 
This Is My Code Of Javascript  
 
 
<script>
$("#category").on('submit', function (e) {
debugger;
var Category1 = $("input[name='[0].Category']").val();
var Category2 = $("input[name='[1].Category']").val();
var Category3 = $("input[name='[2].Category']").val();
var Category4 = $("input[name='[3].Category']").val();
var Category5 = $("input[name='[4].Category']").val();
if (Category1 == "") {
swal("Category Must Be enter");
return false
}
if (Category2 == "") {
swal("Category Must Be enter");
return false
}
if (Category3 == "") {
swal("Category Must Be enter");
return false
}
if (Category4 == "") {
swal("Category Must Be enter");
return false
}
if (Category5 == "") {
swal("Category Must Be enter");
return false
}
//This Is Code For Duplication
 
var names = [Category1, Category2, Category3, Category4, Category5];
 
var uniqueNames = [];
$.each(names, function (i, el) {
e.preventDefault();
if ($.inArray(el, uniqueNames) === -1) {
uniqueNames.push(el);
}
else {
swal("Duplication Not Allow");
return false;
}
});
})
</script>
 
 
 

Answers (2)