javascript find an object with specific properties in an array -


i need make extension existing code, can't change it. there's array:

var availabletags = [         { label: "yoga classes", category: "educational" },         { label: "cooking classes", category: "educational" },         { label: "cheese tastings", category: "educational" },         { label: "maker workshops", category: "practical" },         { label: "seminars", category: "practical" },         //many more of these ]; 

now need check if text entered in input box included in 1 of labels, e.g. if user enters "yoga classes" => ok, if "yoga" => nok, "sdsdf" => nok, etc.

what best way this? not sure can use array.indexof not sure how pass object function, try looping through array (around 40 entries) , compare each object.

you can use array.some method:

tests whether element in array passes test implemented provided function.

then code like:

var isfound = availabletags.some(function(el) {     return el.label === 'yoga classes'; }); 

note: some method needs shimmed.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -