Three possibilities here:
The "Cash Flow" property is inherited, or
The "Cash Flow" property is non-enumerable, or
Both. :-)
Object.keys only gives you the names of the enumerable, own properties of an object. Both inherited and non-enumerable ones are skipped.
You can use for-in to access all enumerable properties, including inherited ones:
var proto = {"Cash Flow": 90254};
var obj = Object.create(proto);
obj.barTitle = 'Cash Flow';
// Doesn't show
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key]);
});
console.log("----");
// Shows:
for (var key in obj) {
console.log(key, obj[key]);
}
You can use Object.getOwnPropertyNames to get all "own" properties of an object, including non-enumerable ones (this was new in ES5 [2009]):
var obj = {barTitle: "Cash Flow"};
Object.defineProperty(obj, "Cash Flow", {
value: 90254
});
// Doesn't show
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key]);
});
console.log("----");
// Shows:
Object.getOwnPropertyNames(obj).forEach(function(key) {
console.log(key, obj[key]);
});
If you need all properties with String names, including inherited non-enumerable ones, you can easily combine Object.getOwnPropertyNames with Object.getPrototypeOf (new in ES2015) to build a loop:
var proto = {};
Object.defineProperty(proto, "Cash Flow", {
value: 90254
});
var obj = Object.create(proto);
obj.barTitle = "Cash Flow";
// Doesn't show
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key]);
});
console.log("----");
// Shows:
getAllPropertyNames(obj).forEach(function(key) {
console.log(key, obj[key]);
});
function getAllPropertyNames(obj) {
var names = Object.create(null);
var p = obj;
while (p && p !== Object.prototype) {
Object.getOwnPropertyNames(p).forEach(function(name) {
names[name] = true;
});
p = Object.getPrototypeOf(p);
}
return Object.keys(names);
}
In that, I've assumed you don't want to see the properties of Object.prototype, so we stop early if it's in the prototype chain of the object.
Also note that I've assumed you aren't interested in Symbol-named properties. If you are, use Object.getOwnPropertySymbols to access them.
'Cash Flow' : 90254[<>]toolbar button). There's no reason that the property should be undefined assuming the object is actually correctly created: jsfiddle.net/txxj7fhx{"barTitle": "Cash Flow", "Cash Flow": 90254}