0

I want to get only the AID from the solution now i am getting. I tried rows[0] but was not successful.

Code:

console.log('The solution is: ', rows);

Output:

The solution is:
[ { AID: 6520,
    DID: 113071,
    TITLE: 'First Knight',
    DATE: '7/7/1995',
    SCORE: 89 } ]

2 Answers 2

1

Use rows[0]["AID"] to access the AID property.

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

2 Comments

rows[0].AID is a usually preferred notation
Thanks for the heads up. :)
0

Let's understand your overall data structure here:

var rows = [ 
 { 
    AID: 6520,
    DID: 113071,
    TITLE: 'First Knight',
    DATE: '7/7/1995',
    SCORE: 89 
  } 
];

The variable rows is an array of objects. Thus rows[n] gets you a specified object in that array and therefore rows[0] is the first object in the array which would be:

 { 
    AID: 6520,
    DID: 113071,
    TITLE: 'First Knight',
    DATE: '7/7/1995',
    SCORE: 89 
  } 

So, now you want to access the AID property in that object so you can just do:

rows[0].AID

And, here's a working snippet demo:

var rows = [ 
 { 
    AID: 6520,
    DID: 113071,
    TITLE: 'First Knight',
    DATE: '7/7/1995',
    SCORE: 89 
  } 
];

document.write(rows[0].AID);

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.