Check out v4 of the Fauna CLI
v4 of the Fauna CLI is now in beta. The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start. |
Object.hasPath()
Test if an Object has a property.
Examples
Basic example
// Test if the Object contains the top-level `foo` property.
Object.hasPath({ foo : 'bar' }, ['foo'])
true
Property that doesn’t exist
// Test if the Object contains the top-level `baz` property.
Object.hasPath({ foo : 'bar' }, ['baz'])
false
Nested property
// Defines an Object with customer data.
let customer = {
"name": "Ruby Von Rails",
"email": "ruby@example.com",
"address": {
"street": "87856 Mendota Court",
"city": "Washington",
"state": "DC",
"postalCode": "20220",
"country": "US"
}
}
// Test if the customer Object contains the
// nested `address.state` property.
Object.hasPath(customer, ['address', 'state'])
true
Nested property that doesn’t exist
// Defines an Object with customer data.
let customer = {
"name": "Ruby Von Rails",
"email": "ruby@example.com",
"address": {
"street": "87856 Mendota Court",
"city": "Washington",
"state": "DC",
"postalCode": "20220",
"country": "US"
}
}
// Test if the customer Object contains the
// nested `address.zipCode` property.
Object.hasPath(customer, ['address', 'zipCode'])
false
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!