I would like to creat an array that includes every products id’s from the local storage object of my shopping website cart. The thing is the function that i made generate an array for each product’s id instead of one array with all the product’s id in it
var cartStorage = JSON.parse(localStorage.getItem("cart"));
cartStorage.forEach(function (cart, index) {
let cartIds = [cart._id];
console.log(cartIds); // logs one array for each id instead of just one array with every id's
});
I’ve been trying for hours but nothing seems to work, i’m guessing i have to use a forEach() but i can’t make that work?