Linked Questions

505 votes
16 answers
208k views

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 ...
Mark Renouf's user avatar
  • 31.1k
-1 votes
1 answer
171 views

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 ...
Totem's user avatar
  • 7,379
0 votes
1 answer
130 views

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 ...
ArchNoob's user avatar
  • 4,146
-1 votes
2 answers
63 views

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....
Matus Dubrava's user avatar
1 vote
2 answers
38 views

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. ...
George's user avatar
  • 7,357
15 votes
4 answers
5k views

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 ...
streetlight's user avatar
  • 5,978
2 votes
1 answer
7k views

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 ...
purudpd's user avatar
  • 179
2 votes
3 answers
1k views

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"}); //...
lgm42's user avatar
  • 621
2 votes
3 answers
2k views

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 = { ...
Tsuna's user avatar
  • 2,196
1 vote
3 answers
443 views

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 ...
Atmega 328's user avatar
0 votes
3 answers
403 views

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 ...
austinc's user avatar
  • 283
-2 votes
5 answers
123 views

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 ...
Christian F's user avatar
0 votes
2 answers
94 views

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 ...
badso's user avatar
  • 109
1 vote
2 answers
31 views

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 ...
Rajesh Kumar Tonukunoori's user avatar