Linked Questions
14 questions linked to/from difference between dot notation and bracket notation in javascript
505 votes
16 answers
208k views
JavaScript property access: dot notation vs. brackets?
Other than the obvious fact that the first form could use a variable and not just a string literal, is there any reason to use one over the other, and if so under which cases? In code: // Given: var ...
-1 votes
1 answer
171 views
Notation for referencing object properties in for loop [duplicate]
I am currently going through the javascript track on codeacademy.com. The current lesson asked me to do this, which will print out the value of each property: var nyc = { fullName: "New York ...
0 votes
1 answer
130 views
How to use variables in Meteor Template helpers [duplicate]
I have made a function that will deal with many templates on created and destroy. Since writing each template helper(created/destroyed) will be repeatable I thought of making a templates array, and a ...
-1 votes
2 answers
63 views
.(dot) vs [ ] property assignment result differs for copied object [duplicate]
I have stumbled upon something that bugs me. I had to copy one object so I have written a helper function for that task. function deepCopy2(target, obj) { for (var prop in obj) { if (obj....
1 vote
2 answers
38 views
Using the value of a variable to access a property of an object [duplicate]
var fruit = {apple:"1", banana:"2"}; var w = "apple"; console.log(fruit.w); //this is problematic I am trying to use this logic in my code to display the value "1" in the console. This doesn't work. ...
15 votes
4 answers
5k views
Why does JSLint prefer dot notation over Square Bracket?
I've been linting some of my code and got some errors back saying it is better to use dot notation. I found out I was using square bracket notation (with clarity from this great post), however, I ...
2 votes
1 answer
7k views
Accessing object properties in javascript using for loop?
consider the following object: var nyc = { fullName: "New York City", mayor: "Bill de Blasio", population: 8000000, boroughs: 5 }; when i try to access each of the properties using for loop: for(var ...
2 votes
3 answers
1k views
Build a dynamic json tree
I would like to make a JSON tree from an array. My array is formed like that : var arraySource = []; arraySource.push({key : "fr", value: "france"}); arraySource.push({key : "es", value: "spain"}); //...
2 votes
3 answers
2k views
javascript - dot vs bracket notation in enumeration
I do know there's some differences between dot and bracket notations but for this specific problem I am a bit confused why the dot notation wouldn't work and bracket does. var rockSpearguns = { ...
1 vote
3 answers
443 views
document[] - src.charAt - src.length
document[] src.charAt src.length What are these three things? I am sure that pixState will give me a 1 or a 0; var pixState = document[imgName].src.charAt((document[imgName].src.length) - 5) Here ...
0 votes
3 answers
403 views
Parse JSON in children element in order
Here is the JSON example: jsonData: { "Device": { "Content": { "UL": { "index0": "12", "index1": "1", .... "index31": "5", } } } } This is what I tried, but it didn't work: var index = []; var ...
-2 votes
5 answers
123 views
Wrong approach to dot notation?
I have a object that looks like this: var obj = { Laser: [0, 2], Missile: [4, 4] } using literal notation, i can access the properties just fine: for (prop in obj){ console.log(prop + " scored ...
0 votes
2 answers
94 views
Js Object Mapping
What does the var brackets = { '(': ')', '{': '}', '[': ']' }; From the following code do? Can you give examples of this kind of object in use? I know that objects can have ...
1 vote
2 answers
31 views
Why two ways are allowed to access json keys in angularjs?
Below is my code snippet <body ng-app='abc' ng-controller='MainCtrl as ctrl'> <div ng-repeat="note in ctrl.notes"> <span class="label"> {{note[1]}}</span> <span ...