deepFindById

Function

Traverse a graph, locating the first entry with an id property that has a specific string or number value

const l = {
 one: {
   two: [
     {
       id: "n001",
       color: "red"
     },
     {
       id: "n002",
       color: "yellow"
     }
   ]
 }
};

const config = deepFindById(l, "n002")
//> {id: "n002", color:"yellow"}

This was designed to search a Site/Page/Project layout, and return the config for a card. There was some concern about the performance and using a real layout object, in the test, it takes ~1.5ms to do the search.

  • deepFindById(object: any, value: string | number) : any

Parameters

Parameter Type Default Notes
object Required any
value Required string | number

Returns

any

Function defined in common/src/objects/deepFind.ts:37