JS - jQuery inarray ignoreCase() and contains()

前端 未结 2 1405
北恋
北恋 2021-01-18 02:53

well, I am more of a PHP person, and my JS skills are close to none when it comes to any JS other than simple design related operations , so excuse me if I am asking the obv

2条回答
  •  -上瘾入骨i
    2021-01-18 03:44

    To check if an array contains an element, case-insensitive, I used this code:

        ret = $.grep( array, function (n,i) {
            return ( n && n.toLowerCase().indexOf(elem.toLowerCase())!=-1 );
        }) ;
    

    Here is a fiddle to play with array match case insensitive

提交回复
热议问题