Send alert if item has already been selected

public onSubmit(id, product_name){

var data = {
localStorage.setItem(this.storageKey, JSON.stringify(this.items));

var retrieverObject = localStorage.getItem('id');
var retrieveObject = JSON.parse(retrieverObject);
if (retrieveObject == id) {

I want to check if the value has already been submitted. This is part of a shopping cart application in which the product quantity will be updated if the product has already been chosen.

Simply add an javascript alert box and it got u covered
You can use HTML/Bootstrap for this as well

I think that getItem returns an array. I will check it out when I get home from work.

getItems is getting the products ID and not the items ID. But when I use getItem(, it returns null.

When I use localStorage.getItem(‘MyDataStorageKey’), it returns:

[{“id”:0,“product_name”:“Adult Male Bike”},{“id”:0,“product_name”:“Adult Male Bike”}] so I tried ‘’ and ‘MyDataStorageKey[id]’ but they both returned null.

localStorage.getItem(‘MyDataStorageKey[“id”]’) returns null

All of these return null:
var retrieverObject = localStorage.getItem(‘items[“id”]’);
var retrieverObject = localStorage.getItem(‘items[0].id’);
var retrieverObject = localStorage.getItem(‘items[{“id”}]’);

This is the solution:

var retrieverObject = localStorage.getItem('items');
var retrieveObject = JSON.parse(retrieverObject);
if(retrieveObject === null) {
  console.log('no tasks')
} else {
   alert("This is the storage id " +;
   if ( == id){
   alert( + " same ");