Skip to content

Instantly share code, notes, and snippets.

@bhaireshm
Created June 18, 2021 09:58
Show Gist options
  • Save bhaireshm/299bb885ad7f6b443e7917b82b715979 to your computer and use it in GitHub Desktop.
Save bhaireshm/299bb885ad7f6b443e7917b82b715979 to your computer and use it in GitHub Desktop.
Add or delete an element from an array.
/**
* @param arr: Array
* @param ele: element to be added
* @param remEle: element to be deleted
*/
function addDelEleFromArray(arr = [], ele = "", remEle = "") {
if (ele && !arr.some((a) => a == ele)) arr.push(ele);
if (remEle) return arr.filter((a) => a != remEle);
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment