I want to implement a system that creates an object and adds it to an array whenever new data is entered and the 'add' button is pressed. However, I'm unsure of the correct way to add a new object to an array. Also, for some reason, my code is not displaying in the yellow box.
var products = [];
class Product {
constructor(productname, cost, quantity){
this.productname = productname;
this.cost = cost;
this.quantity = quantity;
}
}
function addProduct(){
var productname = document.getElementById('productName').value;
var cost = document.getElementById('cost').value;
var quantity = document.getElementById('quantity').value;
tbody += '<tr><td>' + productname + '</td><td>' + cost + '</td><td>' + quantity + '</td><td>' + test + '</td><tr>';
document.getElementById('tablebody').innerHTML = tbody;
product();
function product(){
products.push(new Product(productname, cost, quantity));
}
}