Skip to content

Instantly share code, notes, and snippets.

@xtbl
Last active January 1, 2016 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtbl/8127057 to your computer and use it in GitHub Desktop.
Save xtbl/8127057 to your computer and use it in GitHub Desktop.
get all the keys of an object
it('should get all the keys of an object', function() {
var selectedTile = { $$hashKey: 'testId', obj1:'test', obj2:5, obj3:{ test1:'test',test2:{a:1,b:2} } };
var selectedTile2 = { $$hashKey: 'testId', obj1:'test', obj2:5, obj3:{ test1:'test' } };
var keyList = [];
var recursiveEach = function(obj, customFunc) {
// using recursive each because _.each/_.keys only gets first level properties
for (var k in obj) {
if (typeof obj[k] == "object" && obj[k] !== null){
customFunc(k);
recursiveEach(obj[k], customFunc);
}
else {
customFunc(k);
}
}
};
var pushKey = function(k) {
keyList.push(k);
};
recursiveEach(selectedTile,pushKey);
expect(true).toBe(true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment