javascript - js, $.inArray, not returning expected returns -
i want inquire question why not working?
http://jsfiddle.net/2fmue/4/
var = $('input').attr('value').split(','); if(a instanceof array) alert(1); if($.inarray($('#id').text(), a)) alert(2); if($.inarray('united state', a)) alert(3); // array no homecoming right match.
i split value array , utilize $.inarray check string has in array.
but not homecoming right index.
i dont know wrong in example. please advice.
thank much.
it works well.
$.inarray
returns index of element found in given array (or -1
if not found).
as example,
$.inarray("united state", ["united state", "america"]) === 0 $.inarray("unknown", ["united state", "america"]) === -1
so, in order check if element exists in array have use:
if ($.inarray("unknown", ["united state", "america"]) > -1) { // ... }
javascript jquery arrays match
No comments:
Post a Comment