Day 72.
Question 1.
I'm trying to understand filter() method better, so I can use it to delete a specific item in an array. I understand examples where there's only one parameter passed into a callback function but not with two parameters. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#affecting_initial_array_modifying_appending_and_deleting
So under Syntax section, I get that element
is the current item being processed in the array, and it says index
is the index of the current element being processed in the array. I don't quite understand index
part and how it'd be useful
(I'm only looking at cases with 2 parameters so I modified the example to have only 2, and deleted arr
)
words = ["spray", "limit", "exuberant", "destruction", "elite", "present"]; const deleteWords = words.filter((word, index) => { return word.length < 6; });
Tbh I don't think this is an appropriate example for me at the moment, cause it's not using the second parameter
index
, the result is the same whether or not I specify theindex
. I was wondering why MDN would use the second parameter if that's the case. The index of each element doesn't seem to be all that important for this example.
Question 2.
Is there a way to redo all these options?
I didn't know I should've done otherwise as the article https://www.digitalocean.com/community/tutorials/linting-and-formatting-with-eslint-in-vs-code suggested.
\=> I can just run npm init @eslint/config
command again.