Created
April 23, 2009 01:27
-
-
Save edspencer/100215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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