A
A
Artem2020-04-29 08:35:20
JavaScript
Artem, 2020-04-29 08:35:20

How to make a selection from an object?

It is necessary to add one element to "localstorage", let's say "{2021:1}" , but not all at once.

var items = { 2021: 0, 2022: 0, 2023: 0, 2024: 0 };

out1 += '<button class="number" data-art="' + key + '">' + items[key] + '</button>';

function plus() {
    var articul = $(this).attr('data-art');
    if (cart[articul] != undefined) {
        cart[articul]++;
    }
    else {
        cart2[articul] = 1;
    }
    localStorage.setItem('cart', JSON.stringify(cart)); 
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-04-29
@shylov

So what's the problem?

localStorage.setItem('cart', JSON.stringify({[2021]: cart[2021]}));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question