find a specific string pattern in an array jquery

Posted by Bwyss on Stack Overflow See other posts from Stack Overflow or by Bwyss
Published on 2013-11-04T09:51:18Z Indexed on 2013/11/04 9:53 UTC
Read the original article Hit count: 164

Filed under:
|

Apologies if this is a duplicate, but I can't seem to find the solution. I am trying to find a specific string pattern in an array. I want to find all values in data that contain 'underscore r underscore'. I then want to create a new array that contains only those keys and values.

var data = ["something", "bar_r_something"];
var resultArray = new Array();    
for (var i = 0; i < data.length; i++) {
    var bar = /_r_/;
    if ($.inArray(bar, data[i].length) > 0)
    {
       console.log("found _r_");
       resultArray.push(data[i]);
    }
};

I just can't seem to get that $.inArray to work, it seems to always kick out -1.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about arrays