+ 2
Whay the callback function takes to parameters to remove duplicates array and explain what does "names.indexOf(v)===i" do?
let names = ['John', 'Paul', 'George', 'Ringo', 'John']; let filtering = names.filter((v,i) => names.indexOf(v) === i ) Console.log(filtering)
2 ответов
+ 2
callback used in almost array methods wich have one receive up to 3 arguments: value, index, array... so you could also write:
let filtering = names.filter(
(v,i,a) => a.indexOf(v)==i
);
One exception is the reduce method, wich take first a fourth argument (the accumulator)...
+ 1
Thank you my bro