Object.keys() returns an array of the keys in the object. You need to select the key for index your looping over. You were close but no cigar.
see fiddle: http://jsfiddle.net/pzky9owf/1/
var modelName = {
name: {
APPLE: true,
ORANGE: true
}
},
fruitRulesRules = [];
for (var i = 0; i < 2; i++) {
fruitRulesRules.push({
field: 'fruitName',
subType: 'equals',
/*
This bit was close. You could could also cache the Object.keys in
another variable so its not called in every itteration of the loop if it doesnt change often
*/
name: Object.keys(modelName.name)[i]
});
}
console.log(fruitRulesRules);
EDIT: Also you've got Object.Keys, capital K, its lower case k but i presume that's a typo writing the fiddle.
EDIT AGAIN: As @KrzysztofSafjanowski mentioned in another comment you can't guarantee the order of Object.keys() so even though above works it may not give the desired results.
Ive updated the fiddle to show a different way where the order of the keys is not important: http://jsfiddle.net/pzky9owf/2/