1

I am pretty new to JavaScript and Mysql. MySQL query (which I have run in my server-side code in JS) returns rows in this form

i.e. console.log(rows) gives:-

[ RowDataPacket {
    id: 7080,
    post_author: 134,
    post_title: '99 Varieties Dosa, Indira Nagar',
    post_content: 'There',
    link: '99-varieties-dosa-indira-nagar',
    seo_keywords: null,
    seo_desc: null,
    seo_title: null,
    best_for: 'Dosas',
    special_info: '',
    also_serves: 'Dosas',
    'close-timing': '',
    address: '56, 9th A Main Road',
    direction_landmarks: 'Located in Indira Nagar',
    seating: 'Unavailable',
    longitude: '77.64097630979995',
    latitude: '12.9777060556',
    phone_no: '   ',
    image_url: null,
    location: 'Indira Nagar',
    cuisine: 'South Indian Tiffin',
    categories: 'Local Food',
    Tags: 'Mysore Masala Dosa' }]
[ RowDataPacket {...}]
[ RowDataPacket {...}]
[ RowDataPacket {...}]
[ RowDataPacket {...}]
    

How can I access the location key of RowDataPacket Object?

I tried rows[i].location, rows[i]["location"], rows.location, rows[i].RowDataPacket.location etc.

Adelin
  • 7,809
  • 5
  • 37
  • 65

1 Answers1

0

When you are doing console.log(rows); you are getting data in the form of JSON array, which can be accessible using below code snippet:

$.each(rows, function(index, data){
// check your index & data details like below & perform other tasks
console.log('INDEX=', index);
consoel.log('DATA=', data);  // Here data will be an object
// to access individual key data like location, you can try below code
console.log('LOCATION=', data.location);
});

For further reference you can go through link: https://api.jquery.com/each/

Prasad Wargad
  • 737
  • 2
  • 7
  • 11
  • Sir how can use jQuery with Node.js? – ABHILASHA Jun 27 '18 at 06:24
  • You question wasn't have tag or any specification related to NODE.JS, so answer was given based on knowledge of JQUERY. For using jquery & node.js in sync you can refer a link: https://stackoverflow.com/questions/1801160/can-i-use-jquery-with-node-js – Prasad Wargad Jun 27 '18 at 06:42