Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Not able to access Data inside Javascript Array

HI ,

 var jsonObj = [] ;
for (var i = 0; i < data.jobs.length; i++) {
 jsonObj.push({id: data.jobs[i].Dater, optionValue: data.jobs[i].INCPU});
 }
alert(jsonObj);

I am getting as result as

[object Object],[object Object],[object Object]

Answer*

Draft saved
Draft discarded
Cancel
9
  • @Marcelo This answer implies that JSON serialization can only be achieved with a separate library. This is of course not true, since all current browsers implement the JSON global object. Commented Apr 18, 2011 at 13:40
  • @Šime: That depends on what you define as current. If you want to support IE7, which still has about 10% of the market, then you'll run into trouble. Also, json2.js automatically falls back on the built-in JSON object, if present, so there is very little to be gained by avoiding it. Commented Apr 19, 2011 at 7:41
  • @Marcelo Let me repeat myself. Your answer implies that JSON serialization can only be achieved with a separate library. "If you want feature X, add library Y to your web-page" implies that library Y (or a similar library) is required for feature X. A more correct answer would be: "If you want feature X, use function Y" (JSON.stringify() in this case), and then "Note: some older browsers (IE6, IE7, FF3 - ~20% of the market) don't implement this function. If you need to support those browsers, add library Z to your web-page". Commented Apr 19, 2011 at 12:23
  • @Šime: There was no need to repeat yourself; I understood you perfectly well the first time. In fact, it appears that it is you who failed to properly read what I wrote. My response to your comment was to the effect that, if you define IE7 as "current" — which I do, since 10% is still a very important segment of the market for most serious websites — then your claim that, "This is of course not true," is patently false. Moreover, you'll note that I never actually repudiated your first sentence. Commented Apr 19, 2011 at 13:04
  • If you really want to split hairs, my answer was either correct or it wasn't. If you can't point to anything I said that was false, then any talk of a "more correct" answer is dubious. My first statement was merely advice, which you can disagree with, but I note that in your suggested amended, you didn't suggest any change to the wording, merely an appended qualifier. Commented Apr 19, 2011 at 13:06

lang-js

AltStyle によって変換されたページ (->オリジナル) /