On this answer, How do I empty an array in JavaScript? it's suggest to set the Array length value to 0, so if A = [0,0,0,0] then A.length = 0 should make it A = [] But I can't achieve that with my code,
I feel like I am literally doing it right but, javascript is printing the wrong variable
my code is this:
client.fetchCart(localStorage.getItem('lastCartId')).then(function(remoteCart) {
console.log(cart);
cart.lineItems.length = 0 ;
console.log(cart.lineItems.length);
console.log(cart.lineItems);
client.updateCart(cart);
});
The cart is logged before the setting an array length to 0, and then logged again after, but in my debugging both of the logged carts have the same lineItems.length. Which means setting it to 0 with cart.lineItems.length = 0 ; hasn't worked :(
any suggestions?