You have to think of the localStorage field as an array with potential data from the beginning.
In code:
// 1. and 2. where `items` is always an array of item-objects with 0..n elements
const items = (() => {
const fieldValue = localStorage.getItem('cart');
return fieldValue === null
? []
: JSON.parse(fieldValue);
})();
// 3.
items.push({"name":"T-Shirt","price":3.99,"quantity":1});
// 4.
localStorage.setItem('cart', JSON.stringify(items));
Or with storejs:
// 1. and 2. where `items` is always an array of item-objects with 0..n elements
const items = store.get('cart') || [];
// 3.
items.push({"name":"T-Shirt","price":3.99,"quantity":1});
// 4.
store.set('cart', items);