Last active
January 1, 2016 09:49
-
-
Save xtbl/8127057 to your computer and use it in GitHub Desktop.
get all the keys of an object
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
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