john john - 1 year ago 81
Javascript Question

How to search for a string inside an array elements using javascript?

var objTittleArr= ["Game of Thrones", "Suits", "Breaking Bad", "Legend of Korra"];

How can i find array items includes a string?

I tried to find array items includes 'orr' as below. where am I going wrong? How can i find them?

for (var j=0; j<objTittleArr.length; j++) {

if (objTittleArr[j].match(/orr/g))

Answer Source

Remove the j++;, it increments the loop twice each iteration, so you're skipping some elements.

Also, just in case - Legend of Korra needs to be between quotes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download