difference between dot notation and bracket notation in javascript [duplicate]
This question already has an answer here: JavaScript property access: dot notation vs. brackets? 11 answers I am trying to understand the difference between .Notation and [] notation. In my problem below when I use if (object[key] === true) I get the correct answer. When I use if (object.key === true) it does not work. Could someone explain why it's different. var myObj = { one: false, two: false, three: false, four: true, five: false, six: false }; var myFunc = function (object) { for (var key in object) { if (object[key] === true) { return "There is a true value in this object"; } else { } }