SHARE
TWEET

Untitled

a guest Aug 26th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const addElementToArrayUniquely = (element, array) => {
  2.   //will not add element, if it already exists
  3.   let elementAlreadyExist = false;
  4.   array.map(data => {
  5.     if (data.id == element.id) {
  6.       elementAlreadyExist = true;
  7.     }
  8.   });
  9.   if (!elementAlreadyExist) {
  10.     array.push(element);
  11.   }
  12.   return array;
  13. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top