jQuery .inArray() always true?

后端 未结 2 1430
情话喂你
情话喂你 2020-12-01 16:03

I\'m trying to use inarray but its always returning true? Any ideas? (all li\'s are showing)

$(\"#select-by-color-list li\").hide();

// get the select
var $         


        
2条回答
  •  感动是毒
    2020-12-01 16:50

    ES6 to the rescue! Although not jQuery I thought worth answering for future readers...

    ES6 introduces .includes() which works as you think $.inArray SHOULD work:

    const myArray = ["a", "b", "c"];
    
    console.log(myArray.includes("a")) /* true */
    console.log(myArray.includes("d")) /* false */

    Array.prototype.includes()

提交回复
热议问题