Answer the question
In order to leave comments, you need to log in
How to count the number of certain objects in LocalStorage?
Good afternoon, LocalStorage stores several objects that can be conditionally divided into two groups, the first is pairs with the comp-x key, where * - x are numeric indices, and the second is cart-x (with the same history). We need to get two numbers - the number of items with comp-x and the number of items with cart-x. How can I do that?
Answer the question
In order to leave comments, you need to log in
Why don't you write an array of one key at a time?
It would be much more convenient to work with an array:
var cartItems = JSON.parse(localStorage.getItem('cart'));
var itemsQuantity = cartItems.length;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question