Message from JavaScript discussions
September 2017
— I know
#ask
how to filter with more name filter like this:
var func = flight.filter(function(item) {
for (var num = 0; num < item.length; num++) {
return item[num].airline_name == filter[0] || item[num].airline_name == filter[1]
}
});
can i loop filter[]??
— The second parameter passed to the filter function is the index of the current element and the third parameter is the original array on which u run the filter method, why u need a loop ?
— Wat
— This makes no sense
— How to loop item[num].airline_name == filter[num] with num of filter?
— 1. You're assigning the return value of flight.filter
to func
, but it will not return a function, but an array.
2. There is no point in the inner for
-loop, since you return instantly anyway.
3. This code implies that flight
is an array of arrays, is that correct?
— Yes, its array , i want to filter array with more airline name and show
—
var result = flight.filter(function (item) {
return filter.includes(item[0].airline_name);
});
— Try that?
— Or just item.airline_name
and simplify your flight
array
— I try it