I'm writing a code that take user input and stores it in an object array. However it doesn't seem to work the way I want it to. whenever I try to print out the array it just says [object, Object]. Thanks in advance!
let addedProducts = [];
let output = document.getElementById("output");
let productName = document.getElementById("product-name").value;
let productAmount = document.getElementById("amount-stored").value;
const addProduct = () => {
product = {
name: productName,
amount: productAmount
}
addedProducts.push(product.name);
addedProducts.push(product.amount);
document.forms[0].reset();
}
const showProducts = () => {
output.innerHTML = addedProducts;
}
<form>
<label>ProductName</label>
<input id="product-name" type="text"><br>
<label>amount in store</label>
<input id="amount-stored" type="text"><br>
<input type="button" value="add product in array" onclick="addProduct()">
<input type="button" value="show products in array" onclick="showProducts()">
</form>
<p id="output"></p>