Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
const array = ['asad', 'ikhlas', 'umair']

const filterArray = array.filter((elem, index) => {
    return elem === 'asad'
})  

console.log(filterArray)

what is the purpose of index in the above code?

What I have tried:

i have tried but failed to understand
Posted
Updated 6-Jan-21 19:56pm

1 solution

It's an optional parameter that provides the index to the element being processed if you need it: Array.prototype.filter() - JavaScript | MDN[^]
Your code doesn't use it, so you can remove it from the callback if you want.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900