title: How to find if an object exist in an array [array is coming from localstorage]
body: <p>I created an empty array in <code>localStorage</code></p>
  <pre class="lang-js prettyprint-override"><code>localStorage.setItem('items', JSON.stringify([]))
  </code></pre>
  <p>and then fetching that empty array like this :</p>
  <pre class="lang-js prettyprint-override"><code>let fetchedItems = JSON.parse(localStorage.getItem('items'));
  </code></pre>
  <p>After fetching the <code>Array</code> I want to append some objects in the same.</p>
  <p><strong>Array of Objects</strong></p>
  <pre class="lang-js prettyprint-override"><code>let objects = [
    {
       id: '37f60b13-bb3a-4919-beff-239207745343',
       body: '1',
    },
    {
       id: '26c5b0fa-b15f-4a50-9a56-5880727a8020',
       body: '2',
    },
    {
       id: '37f60b13-bb3a-4919-beff-239207745343',
       body: '1',
    },
  ];
  </code></pre>
  <p>The first and last object have same <code>id</code></p>
  <p>Right now what I am doing is, as I don't want to save or append duplicate objects <strong>(by id key)</strong> in <code>array/localstorage</code>:</p>
  <pre class="lang-js prettyprint-override"><code>function saveItemsInLocalStorage(item) {
    let items;
  
    if (localStorage.getItem('items') === null) {
      items = [];
    } else {
      items = JSON.parse(localStorage.getItem('items'));
    }
  
    items.push({
      id: item.id,
      body: item.body,
    });
  
    localStorage.setItem('items', JSON.stringify(items));
  }
  
  objects.forEach((object) =&gt; {
    fetchedItems.forEach((fetchedItem) =&gt; {
      if (fetchedItem.id !== object.id) {
        saveItemsInLocalStorage(object)
      }
    });
  });
  </code></pre>
  <p>The above code is not working. I have also tried <code>reduce</code> method.</p>
  <p><strong>Note</strong> initially array is empty</p>