Looking to create an array that contains all the product IDs stored in the local storage object of my online shopping cart. However, the current function I have generates separate arrays for each product ID instead of consolidating them into one single array.
var cartStorage = JSON.parse(localStorage.getItem("cart"));
let cartIds = [];
cartStorage.forEach(function (cart) {
cartIds.push(cart._id);
});
console.log(cartIds); // should log a single array with all the IDs
I've spent hours trying to figure this out but nothing seems to be working. I think I need to use forEach() but I can't seem to get it right?