0

I want to pull the variables of connectData for some debugging. When I do type of I get object back thinking this was an array and I can do connectData[1] I get undefined,

So if I want to log out just the host name from connectData can someone please show me an example?

var connectData = {
    hostname: 127.0.0.1,
    port: 1521,
    database: "db", // System ID (SID)
    user: "usename",
    password: "password"
}

3 Answers 3

2

This is a javascript object, not an array.

You can access the individual elements by name. So to log just the hostname, you can do:

console.log(connectData.hostname);
Sign up to request clarification or add additional context in comments.

1 Comment

I'm not sure what you mean about format being the issue. Is there some other aspect you are having trouble with? In your example above, the text 127.0.0.1 is not a valid javascript value - it should be wrapped in quotes as a string.
1

You can use a for-each loop to iterate through an object's properties.

var connectData = {
    hostname: '127.0.0.1',
    port: '1521',
    database: "db", // System ID (SID)
    user: "usename",
    password: "password"
};

for (var key in connectData) {
    if (connectData.hasOwnProperty(key)) {
        alert(key + " => " + connectData[key]);
    }
}

Working demo: http://jsfiddle.net/Mp6jS/1/

4 Comments

Here are the results, is there a way to get the value of the keys?hostname=>undefined port=>undefined database=>undefined user=>undefined password=>undefined
I think connectData.key should be connectData[key].
@justZito Sorry about that. I corrected the code and included a working example.
ktm5124, the last thing you need to do is apologize that worked great.
0

Log it to the console. console.log(connectData)

In Chrome, you can view the console by right clicking, selecting "Inspect element", and clicking on the "Console" tab.

Comments

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.