Created
January 3, 2020 11:58
-
-
Save arunkumar413/3087004277ae49512e271608e206f8ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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