简体   繁体   中英

combining two filter functions

I'd like to combine two filter functions I'm using to select a few elements in a table. my code looks like this:

a = $('table td').filter(function(index) {
    return index >= number1
}); 
                        
b = $('table td').filter(function(index) {
    return index < number2
});
                        
merge = $.merge(a, b);

The elements from a have to be first and in one row. so if a returns 3 elements they have to be in one row, follow by the elements from b . how can I achieve that? can I combine the filter functions from above?

you better use .slice method instead of filters, in a way like:

list = $('table td')
merge = [...list.slice(number1), ... list.slice(0, number2)]

or if you really want to use filter then:

list = $('table td')
merge = list.filter((item, i) => (i >= number1 || i < number2)  )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM