Obj = new Object() obj = 77 arr = obj Īlert (arr.deepContains( 'id', 1 ) ) // false, no Object has 'id' = 1Īlert (arr. The includes () method determines whether an array includes a certain value among its entries, returning true or false as appropriate. Var obj = new Object() obj = 22 arr = obj * search all elements in an array for one that has a property key equal to value */Ī = function (key,value) I’m a long time out from my last formal class in programming languages so if this type of search has a particular name, please let me know! Since I find so many great examples online I wanted to give somthing back to the community in the hope that this will save someone time and effort down the line. In my case I wanted to pick out the object from an array that had ‘type’ property equal to a certain string. JavaScript offers several ways to check if an array includes a specific value. There are lots of examples for finding if an array contains a certain specific element, but that wasn’t what I needed. I’m sure that this is online somewhere, but I couldn’t turn it up. ![]() ![]() I needed a bit of JavaScript that would look at an array of objects and see if it contained an element that matched a certain criteria.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |