$.grep()方法可以从数组中过滤出我们想要的结果

var nums='1,2,3,4,5,jquery,css,5'.split(',');

如果我们想找出其中的字符串,可以直接使用$.grep()

nums=$.grep(nums,function(num,index){

//num是数组元素的当前值

//index=当前值的下标

return isNaN(num);

});

console.log(nums);//结果:【"jquery","css"】

自动完成部件

<body>

<label for="autocomplete">选择一个编程语言:</label>
<input id="autocomplete">

<script>
var tags = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ];
$( "#autocomplete" ).autocomplete({
source: function( request, response ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
response( $.grep( tags, function( item ){
return matcher.test( item );
}) );
}
});
</script>

</body>