Check for duplicates in JavaScript Array of Objects
Express.js , Javascript , Uncategorized / July 28, 2019

How to check whether an Array of Objects contain duplicates by key Consider an Array of student Objects with each object having a key id. We have to perform a validation whether multiple objects with the same Id is present in the Array or not.

The above are Arrays of student Objects, one with duplicate id value and one without duplicate id value. To get the  Ids present in the Arrays we need to use the map() Method

  Now we have two Arrays containing all the Id values of Objects.  The first one has unique Ids  and the second one has duplicate Id 42342.   To check for duplicates in Arrays, we can create a set from the array. Sets will only have the unique items in the array

  The second set only has 2 values as one of the values in the Array had a duplicate. So, on comparing the length of the Array and size of the Set  we can determine id  Array has duplicates or not  

  The whole code to check whether an Array of objects contain key-value duplicates will look like this. We can use this logic…

Web Storage – A comparative study of Local Storage,Session Storage,Cookies,IndexedDB and WebSQL
databases , Javascript , Uncategorized / July 10, 2019

Storages in browsers – Web Storage Web Storage is the storage mechanism that allows Web applications to store data in Web Browsers. The various storage types include Local Storage, Session Storage, Cookies, IndexedDB, Web SQL. These storages are supported by most of the modern-day web browsers and are standardized by the World Wide Web Consortium. Web Storage lets a web application to store data which in turn helps in the effective end to end functionality of the application. Upon inspecting and navigating to the storage in the browser console, we can see what are the various storage mechanisms supported by the browser and data stored in them. FireFox       Chrome Local Storage Local storage is a key-value store that stores values as string. The data stored in local storage does not have an Expiration date and will stay in the browser forever until we clear the browser data using settings or using Javascript. Up to 10MB of data can be stored in most of the browsers and it is 10MB for Local Storage and Session Storage combined in chrome.IE has 10 MB each. Local Storage follows the same-origin policy. The same-origin means that the Protocol(Http/Https), port and the host…

Share this page in social media platforms