Click here to Skip to main content
15,887,267 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: java code on hospital management Pin
ZurdoDev25-Oct-17 1:50
professionalZurdoDev25-Oct-17 1:50 
JokeRe: java code on hospital management Pin
Karthik_Mahalingam31-Oct-17 16:58
professionalKarthik_Mahalingam31-Oct-17 16:58 
Questionhow to calculate the number of working hours in Week excluding Weekends in JavaScript or jquery using Moment.js Pin
Member 1346136812-Oct-17 3:24
Member 1346136812-Oct-17 3:24 
Rant[Repost] how to calculate the number of working hours in Week excluding Weekends in JavaScript or jquery using Moment.js Pin
Richard Deeming12-Oct-17 3:53
mveRichard Deeming12-Oct-17 3:53 
QuestionExecute functions based on certain time delay and ignore other functions execution Pin
Member 1346008011-Oct-17 16:11
Member 1346008011-Oct-17 16:11 
AnswerRe: Execute functions based on certain time delay and ignore other functions execution Pin
Karthik_Mahalingam16-Oct-17 1:31
professionalKarthik_Mahalingam16-Oct-17 1:31 
QuestionJSON with number as key Pin
V.11-Oct-17 2:42
professionalV.11-Oct-17 2:42 
AnswerRe: JSON with number as key Pin
Afzaal Ahmad Zeeshan11-Oct-17 6:37
professionalAfzaal Ahmad Zeeshan11-Oct-17 6:37 
What happens in JavaScript is that everything is possible, even the impossible. Laugh | :laugh:
{ 
    "1" : 
     [
         {
              "field": "value"...
You can access properties in the JavaScript through index notation as well, this is one of the funniest things in JavaScript. This makes it possible to have properties, and attributes in a way that is impossible in other languages directly. JavaScript supports, object.property, object["property"] and much more ways to access the properties, and attach the properties. Thus, when you have a property called (for instance), "object.1", or "object.something-else", then you can access them through index notation and that would be valid JavaScript.

So I am unsure as to what your JSON is like but if the JSON schema is like the following — which indeed is like yours,
var str = "{ \"1\": [{\"field\": \"attr\"}]}";
Then you can execute the following JavaScript and do what you intent to,
JavaScript
var obj = JSON.parse(str);

// Access the object with key "1", then first element inside it, then the field. 
alert(obj["1"][0].field);
Try this, and you will see how strange sometimes JavaScript can be. Try the code online here, [Edit fiddle - JSFiddle](https://jsfiddle.net/afzaal_ahmad_zeeshan/mvbtztpL/)
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~

GeneralRe: JSON with number as key Pin
V.11-Oct-17 20:05
professionalV.11-Oct-17 20:05 
QuestionHow to hide f12 devloper tool from the browser? Pin
Member 1345865211-Oct-17 0:30
Member 1345865211-Oct-17 0:30 
AnswerRe: How to hide f12 devloper tool from the browser? Pin
F-ES Sitecore11-Oct-17 1:03
professionalF-ES Sitecore11-Oct-17 1:03 
QuestionAngular releases Pin
BrunoFaitalaas9-Oct-17 22:36
BrunoFaitalaas9-Oct-17 22:36 
AnswerRe: Angular releases Pin
Nathan Minier10-Oct-17 2:44
professionalNathan Minier10-Oct-17 2:44 
GeneralRe: Angular releases Pin
Karthik_Mahalingam11-Oct-17 21:21
professionalKarthik_Mahalingam11-Oct-17 21:21 
PraiseRe: Angular releases Pin
Jeremy Falcon7-Nov-17 22:30
professionalJeremy Falcon7-Nov-17 22:30 
QuestionWhy not the output is 3 in java script object for the line console.log(home.count) Hope i am making it clear. Pin
Member 110968437-Oct-17 5:14
Member 110968437-Oct-17 5:14 
AnswerRe: Why not the output is 3 in java script object for the line console.log(home.count) Hope i am making it clear. Pin
Richard Deeming9-Oct-17 8:52
mveRichard Deeming9-Oct-17 8:52 
QuestionBug in try catch statement can I can't find where. Pin
Jason Lemon3-Oct-17 16:11
Jason Lemon3-Oct-17 16:11 
GeneralRe: Bug in try catch statement can I can't find where. Pin
PIEBALDconsult3-Oct-17 17:28
mvePIEBALDconsult3-Oct-17 17:28 
QuestionRe: Bug in try catch statement can I can't find where. Pin
Richard MacCutchan3-Oct-17 21:44
mveRichard MacCutchan3-Oct-17 21:44 
AnswerRe: Bug in try catch statement can I can't find where. Pin
Karthik_Mahalingam4-Oct-17 17:53
professionalKarthik_Mahalingam4-Oct-17 17:53 
AnswerRe: Bug in try catch statement can I can't find where. Pin
ZurdoDev11-Oct-17 9:48
professionalZurdoDev11-Oct-17 9:48 
AnswerRe: Bug in try catch statement can I can't find where. Pin
Weavr8-Apr-18 1:58
Weavr8-Apr-18 1:58 
QuestionJavascript Pin
Member 134419482-Oct-17 15:59
Member 134419482-Oct-17 15:59 
AnswerRe: Javascript Pin
Richard MacCutchan2-Oct-17 21:51
mveRichard MacCutchan2-Oct-17 21:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.