I'm trying to create a function to stop the creation of duplicate sub arrays in an array using Jquery's inArray function but it doesnt seem to work. Maybe i am missing something in my code?
function createProduct() {
var name = document.getElementById("productname").value
var myclass = document.getElementById("productclass").value
var model = document.getElementById("model").value
var manufacturer = document.getElementById("manufacturer").value
var sellingprice = document.getElementById("productsellprice").value
var costprice = document.getElementById("productcostprice").value
var quantity = document.getElementById("quantity").value
productobject = [name, manufacturer, model, myclass, sellingprice, costprice, quantity];
var searchvalue = productobject;
*if (jQuery.inArray(productobject, products) == -1) { products.push(productobject) } else if (jQuery.inArray(productobject, products) != -1) {
document.getElementById
("mydiv").innerHTML = "This product already exists, please check catalogue to edit product";
}*
}
i have added the rest of the codeblock to make it readable but focus on the if block calling the inArray function because somehow, duplicate products still gets added