Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const deepContainsProperty = (data, testProperty) => {
- const hasProperty = testObject => Object.keys(testObject).includes(testProperty);
- // check if top level object has the property itself before looping
- if (hasProperty(data)) {
- return true;
- }
- let propertyFound = false;
- for (let property in data) {
- const currentProperty = data[property];
- if (typeof currentProperty !== 'object' || Array.isArray(currentProperty)) {
- continue;
- }
- propertyFound = deepContainsProperty(currentProperty, testProperty);
- if (propertyFound) {
- break;
- }
- }
- return propertyFound;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement