Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
object object error? Javascript
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Heaplink" data-source="post: 274514" data-attributes="member: 8966"><p>Don't use document.write - it's bad, slow and really stupid. If you wan't to do DOM manipulation the easiest thing to do is using jQuery.</p><p></p><p>Now for your problem: You cannot write out JavaScript objects, arrays and like to the DOM. The DOM doesn't understand that kind of stuff. If you wan't to see what is in the object use console.log (or console.dir) and look in the Developer Tools of your browser to see output.</p><p></p><p>If you wan't to output to the DOM (page) you have to iterate the list of items, that being an array. So for instance you wan't your list of items to look something like this:</p><p></p><p>[CODE][</p><p>{</p><p> "text": "My new reminder",</p><p> "date": "<maybe some date here as string>"</p><p>}</p><p>][/CODE]</p><p></p><p>This is an array with an object. You can add multiple objects to this array and iterate with either for-loop or forEach function:</p><p></p><p>[CODE]myArray.forEach(function(reminder) {</p><p> // output e.g. reminder.text and reminder.date</p><p> // or do DOM manipulation.</p><p>});[/CODE]</p><p></p><p>or a simple faster for loop that is browser compatible:</p><p></p><p>[CODE]for(var i = 0, l = myArray.length; i < l; ++i) {</p><p>var reminder = myArray[i];</p><p>// DOM Manipulation</p><p>}[/CODE]</p></blockquote><p></p>
[QUOTE="Heaplink, post: 274514, member: 8966"] Don't use document.write - it's bad, slow and really stupid. If you wan't to do DOM manipulation the easiest thing to do is using jQuery. Now for your problem: You cannot write out JavaScript objects, arrays and like to the DOM. The DOM doesn't understand that kind of stuff. If you wan't to see what is in the object use console.log (or console.dir) and look in the Developer Tools of your browser to see output. If you wan't to output to the DOM (page) you have to iterate the list of items, that being an array. So for instance you wan't your list of items to look something like this: [CODE][ { "text": "My new reminder", "date": "<maybe some date here as string>" } ][/CODE] This is an array with an object. You can add multiple objects to this array and iterate with either for-loop or forEach function: [CODE]myArray.forEach(function(reminder) { // output e.g. reminder.text and reminder.date // or do DOM manipulation. });[/CODE] or a simple faster for loop that is browser compatible: [CODE]for(var i = 0, l = myArray.length; i < l; ++i) { var reminder = myArray[i]; // DOM Manipulation }[/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
object object error? Javascript
Top