Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
How can I remove the particular item from the array loop if the condition matches?
array.map(item => { item.id === companyId ? //how to remove this item from the array?? } : null)
Thanks in advance
array.filter( item => item.id !== companyId ).map( ... )
You can use the native JS .filter method
.filter
const newArray = array.filter(item => item.id !== companyId)
This will return a new array without the matching item.
Add a comment
You can use the the filter function:
filter
var data = [{id: 1}, {id: 2}, {id: 3}]; const result = data.filter(val => val.id != 2); console.log(result);
_.remove
const newArray = _.remove(array, item => item.id === companyId)
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
array.filter( item => item.id !== companyId ).map( ... )