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
Post a Comment