You can use Array.prototype.every()
var check = [item, item.integrations, item.integrations.slackData]
.every(function(element) { return element });
Edit, Updated
As noted at comments by @FelixKling, the pattern at above using .every()
will fail if item.integrations
is undefined.
Given the example object at Question you can use JSON.stringify()
, String.prototype.match()
with RegExp
/"integrations":|"slackData":|"url":/g/
, then check that .length
of resulting array, if any, is equal to the number of properties expected; in the present case 3
.
A javascript
object which is passed to JSON.stringify()
should have properties with the following pattern:
"
followed by property
followed by "
followed by :
. Depending on the source object, the RegExp
can be further adjusted to meet the specific properties and values of that object.
JSON.stringify(item).match(/"integrations":|"slackData":|"url":/g).length === 3
Note that JSON.stringify()
has a replacer
option which can be used to match properties of the object. The replacer
function option is recursive. See also
but I'm wondering if there's a better way to do this kind of check in
ES6:
The present Answer does not attempt to indicate that using JSON.stringify()
and RegExp
to match or filter a javascript
object is "better"; but only that the approach can meet the described requirement at the present Question.