I have saving cart items in localStorage of javascript. I use product_id for index of array in javascript, this array contain of object with some property.
let cart = JSON.parse(localStorage.getItem('cart'));
cart[cartObject.product_id] = {
quantity : cartObject.product_quantity,
price : cartObject.product_price,
holding : cartObject.product_holding
}
localStorage.setItem('cart' , JSON.stringify(cart));
the problem is for example when my product_id is 8, localStorage is :
0: null
1: null
2: null
4: null
5: null
6: null
7: null
8: {quantity: 15, price: 16000, holding: 44}
what about 4000 ? is localStorage goes overflow ?
this problem does not exist in php, I want to access directly to specific index of array.
for example get cart[4432].price.
how to do that ?
thanks in advance
card[4432]in JavaScript. Array can accept any index, but for performance reasons is advised to use objects if the indices are sparse