Skip to content

Instantly share code, notes, and snippets.

@edspencer
Created April 23, 2009 01:27
Show Gist options
  • Save edspencer/100215 to your computer and use it in GitHub Desktop.
Save edspencer/100215 to your computer and use it in GitHub Desktop.
propertiesExist = function(object, properties) {
var allExist = true;
properties = properties || {};
Ext.each(properties, function(property) {
var splits = property.split('.');
var currentObj = object;
Ext.each(splits, function(currentProperty, index, all) {
if (!allExist) return false;
currentObj = currentObj[currentProperty];
if (!currentObj) allExist = false;
});
});
return allExist;
}
//Usage
var myObj = {a: {b: {c: 'd'}}, '1': {'2': '3'}};
propertiesExist(myObj, 'a.b.c'); // => returns true
propertiesExist(myObj, 'a.b.c', '1.2'); //returns true
propertiesExist(myObj, 'd'); //returns false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment