0

I'm learning Node.js and using mssql to retrieve employee data. I get the following recordset back and having trouble grab the first and last name:

{ recordsets: [ [ [Object] ] ],
  recordset: [ { uid: 'jd123', fName: 'John', lName: 'Doe' } ],
  output: {},
  rowsAffected: [ 1 ] 
}

I have tried the following but had no luck:

D:\LearnNodeJs\Udemy\routes\processes.js

// var submitter = recordset[0]['fName']; // TypeError: Cannot read property 'fName' of undefined
                               ^
//var submitter = recordset[0].fName; // TypeError: Cannot read property 'fName' of undefined
var submitter = recordset.fName; // undefined

console.log(submitter);
1
  • recordset is a property of some object, what is the object name Commented Jan 17, 2018 at 0:50

2 Answers 2

1

Seems you are doing it right

https://jsfiddle.net/9co7wf5t/

const response = {
    recordsets: [ [ [Object] ] ],
  recordset: [ { uid: 'jd123', fName: 'John', lName: 'Doe' } ],
  output: {},
  rowsAffected: [ 1 ] 
};

console.log(response.recordset[0].fName);
Sign up to request clarification or add additional context in comments.

1 Comment

Although the suggestion above worked I accepted this method because it easier to use in my opinion. Thank you Bergur!
0

what is the name of your object? try:

const firstNames = someObject.recordset.map(record => record.fName) to get the first name(s). modify on that as needed to get what you want.

2 Comments

Hi, HolyMoly, thanks for your repsonse. The object is data.
Thank you, I was able to get the first name back with the following code. const firstNames = data.recordset.map(data => data.fName); console.log(firstNames);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.