Trying to create a search input and object display
Hello, I was researching all the different methods that arrays come with, and started to create a big page of notes so I could reference the info for later. As I was doing this is dawned on my I should try and write a js program that could make it easier to access the various methods.
I wanted to make each note as an object with a Title, Example, and description. I set up a function to create these properties. I made a basic page with an input area for the user to search for the array method. Currently the input area is just for show. Im trying to ass just an "onclick" function that will display the object in the <div> below. I'm having a tough time getting the object to write out. Any help would be greatly appreciated. Hopefully my description makes sense. Here is a link to the current code.
Posted Sep 19, 2016, 7:05 PM UTC
When you convert a generic object to a string - which is whats happening when you're assigning it to
textContent- it will default to the string '[object Object]' which is what I assume you're seeing? If you want to see the object properties, an easy way to do that is to throw your object in aJSON.stringify()call when setting the text. This doesn't give you the formatting you'll ultimately want, but good to see what properties are there.Ultimately you'll want to pull out the properties individually and place them in a template or something to format it appropriately.
Ty for the reply, could you point me in the direction of how I would format the object in an easy to read sorta way?
Something like this:
senocular, this is like the third time you have helped me out. I really appreciate you taking the time to help me learn!