Skip to content

Instantly share code, notes, and snippets.

@arunkumar413
Created January 3, 2020 11:58
Show Gist options
  • Save arunkumar413/3087004277ae49512e271608e206f8ff to your computer and use it in GitHub Desktop.
Save arunkumar413/3087004277ae49512e271608e206f8ff to your computer and use it in GitHub Desktop.
var data = [{id:1, name:'Arun'}, {id:1, name:'Arun'}, {id:1, name:'Arun'}, {id:3, name:'Tom'}]
var removeFirstItem = (id) => {
var itemAlreadyRemoved = false
return data.filter(row => {
if(row.id === id && !itemAlreadyRemoved){
itemAlreadyRemoved = true;
return false;
}
return true;
});
}
var newList = removeFirstItem(1);
console.log(newList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment