古詩詞大全網 - 成語大全 - jquery怎麽判斷值是否存在於數組中

jquery怎麽判斷值是否存在於數組中

var?arr?=?[?4,?"Pete",?8,?"John"?];

jQuery.inArray("John",?arr);?//3

jQuery.inArray(4,?arr);?//0

jQuery.inArray("David",?arr);?//-1

jQuery.inArray("Pete",?arr,?2);?//-1