MCPcopy
hub / github.com/parse-community/parse-server / findObjectWithKey

Function findObjectWithKey

src/RestQuery.js:1360–1381  ·  view source on GitHub ↗
(root, key)

Source from the content-addressed store, hash-verified

1358// Finds a subobject that has the given key, if there is one.
1359// Returns undefined otherwise.
1360function findObjectWithKey(root, key) {
1361 if (typeof root !== 'object') {
1362 return;
1363 }
1364 if (Array.isArray(root)) {
1365 for (var item of root) {
1366 const answer = findObjectWithKey(item, key);
1367 if (answer) {
1368 return answer;
1369 }
1370 }
1371 }
1372 if (root && root[key]) {
1373 return root;
1374 }
1375 for (var subkey in root) {
1376 const answer = findObjectWithKey(root[subkey], key);
1377 if (answer) {
1378 return answer;
1379 }
1380 }
1381}
1382
1383module.exports = RestQuery;
1384// For tests

Callers 1

RestQuery.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected