1

This line:

alert("<b>feeds.entries["+j+"] is </b>=>"+feeds.entries[j]+"<br>");

gives this result:

<b>feeds.entries[0] is </b>=>[object Object]<br>

I would like to print the list of objects so that I can use them.

This array is being called as such:

var entry=feeds.entries[i];

and entry.title, prints the title of the image. I guessed at "title", and would like to see all the other objects feeds.entries[] contains, but my alert above, prints "[object Object]". The script is zRSSFeed which is an RSS parser. I'm trying to parse a Menalto Gallery 2 (or g2) RSS feed.

1
  • 2
    Post the code where you construct the feeds and entries objects. Commented Jul 19, 2011 at 17:24

5 Answers 5

2

You can't render string and object together as they are different type. do print object separately alert(feeds.entries[j]). I think it is good to use console.log instead of alert for debugging.

Sign up to request clarification or add additional context in comments.

Comments

1
function join(obj) {
    var ret = '';
    for (var i in obj) {
        if (!obj.hasOwnProperty(i)) continue;
        ret += i + ': ' + obj[i]
    }
    return ret;
}

Call it like this:

alert("<b>feeds.entries["+j+"] is </b>=>"+join(feeds.entries[j])+"<br>");

DEMO

Comments

1

I suggest you download and install Firebug, then read the section on Firebug and logging. It will show you how to log to the console.

I'm also a fan of the YUI 2 Logger which displays the messages in a floating window. Either way, using alert is a sure way to slow down development and drive yourself insane. Development should be more fun than that.

As an aside, take a look at the YAHOO.lang.dump() method which shows what is inside an object. [Object object] isn't very useful as you've discovered.

Comments

1

if you mean to use them in the browser console, use

for (var i==0; i<feeds.entries.length; i++){
   console.log(feeds.entries[i]);
}

otherwise, please explain more clearly what you want, and how you want to represent your objects or their attributes.

Comments

1

Try outputting it as JSON:

alert("<b>feeds.entries["+j+"] is </b>=>"+JSON.stringify(feeds.entries[j])+"<br>");

I don't see why you have the tags in the alert though, as they do nothing.

alert("feeds.entries["+j+"] is =>" + JSON.stringify(feeds.entries[j]));

However, if you are using Chrome, I suggest you simply console.log the object(s) and open up the developer console to view the object.

2 Comments

I don't know how to find, activate, use, etc. the "console log"
If you're on Mac, Cmd+Alt+j. Windows is probably Ctrl-Alt-j. Otherwise, just go to View -> Developer -> Javascript console.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.