Send alert if item has already been selected

public onSubmit(id, product_name){

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

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

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(items.id), 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 ‘MyDataStorageKey.id’ 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 {
  retrieveObject.forEach(function(el){
   alert("This is the storage id " + el.id);
   if (el.id == id){
   alert(el.id + " same ");
   }
  });
}