Retrieve a specific key from SQL records

I have recently started learning JavaScript and MySQL. When I run a MySQL query in my server-side JavaScript code, the returned rows are in the following format:

For example, if I use console.log(rows), it will display:

[ 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 {...}]

My question is, how can I access the location key of the RowDataPacket Object?

I've tried various ways such as rows[i].location, rows[i]["location"], rows.location, rows[i].RowDataPacket.location, etc.

Answer №1

When you use console.log(rows);, the data is returned in JSON array format which can be accessed with the following code snippet:

$.each(rows, function(index, data){
// Check index and data details as shown below and perform additional tasks
console.log('INDEX=', index);
consoel.log('DATA=', data);  // The data here will be an object
// To access specific key data like location, you can use the code snippet below
console.log('LOCATION=', data.location);
});

For more information, you can visit the following link: https://api.jquery.com/each/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

jquery's animation causing elements to move abruptly when containing text

For the past hour, I've been grappling with jQuery and could really use some assistance. The following example showcases smooth animations: when you click on either of the divs, the selected div will move left or right if the viewport is wider than 70 ...

How to use a MySQL query to find multiple search terms within a single column

Imagine a scenario where there is a table with a column named fullName, and it includes the following two names: fullName Peter Andrew Thompson Peter Alan Thompson Jackson Now, picture having a search form where a user enters Peter Thompson. In t ...

I have a task of initiating a request from JavaScript to a PHP file using an API

Seeking assistance! I have two php files named Data.php and Status.php. The task is to send a request to Data.php when data is entered in the zip field, and if the zip code is valid, then send the data to Status.php for parsing the response. Below you will ...

Converting a JSON array of key-value pairs into a Plain Old Java Object (POJO

Is it possible to use Jackson to convert the JSON data below into a POJO class? { "company": [{ "employee": { "address": { "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c7a6a5a487a0aaa6aeabe9 ...

Perform the subtraction operation on two boolean values using Typescript

I'm working with an array: main = [{ data: x, numberField: 1; }, { data: y, numberField: 2; }, { data: x, numberField: 3; }, { data: z, numberField: 4; }, { data: ...

Connect the value of the input field to the dataset

In my current project, I am implementing ng-repeat to showcase a collection of items. Each item includes a line number, an HTML input field for quantity input, and an itemId. I am currently exploring ways to connect the input value with the quantity field ...

What is the method for specifying the HTML file extension within Visual Studio?

I am having issues with my project recognizing the CSS and other files in the HTML files I have created, even though I have double-checked the extension paths. How can I resolve this problem? https://i.stack.imgur.com/85ooE.png https://i.stack.imgur.com/F ...

MySQL 1005 Error - Troubleshooting the Query Issue

I seem to be having trouble identifying the problem with this set of CREATE TABLE queries. I've reviewed it multiple times but I can't pinpoint the mistake. -- ----------------------------------------------------- -- Table `agentes` -- --------- ...

Executing two AJAX requests simultaneously with Django, AJAX, and jQuery in a single event

I believe I'm on the right track to getting this to work, but I could really use some assistance with the JQuery aspect. It seems that everything functions as expected after the second click onwards, but there is an issue with the functionality on the ...

What is the process for loading this image?

While browsing through this stunning website, I came across a feature that caught my eye. Can someone please explain how the designer displayed the "The magic is loading" effect: The image vanishes once the site has finished loading completely. ...

Enhancing JSON Objects in AngularJS with Custom Properties and Calculations

Hello, I'm still getting the hang of angularjs and could use some guidance. I have a Rest service that provides data on saleItems when a get request is made, as shown below: saleItems = [ { "id": 236, "variant": "Oval Holder", "mrp": "6 ...

Unexpected behavior from MYSQL's fetch_assoc() when used with a LEFT JOIN statement

My SELECT query is working perfectly in MySQL Workbench and phpMyAdmin, but when I use $query->fetch_assoc() to display the results on a PHP webpage, the joined column shows up blank for rows that don't have a match in the right-side table. SELECT ...

Tips for incorporating mapbox.js as a background while keeping html content and Navbar consistently displayed on top

I am currently integrating MapBox.js into a Bootstrap 3 website. The main concept is to utilize a map as the background for a row that occupies the full width of the site, with html-content displayed on top. To ensure MapBox.js remains in the background, I ...

Preventing Canvas Image Disappearance with JavaScript's onload Event

My current issue involves adding an Image to my webpage. However, every time I hit the refresh button, the image disappears. After researching on Stack Overflow, it was suggested to include window.onload=yourDrawFunction() in the code. Despite following th ...

Initiate a server application from a client application

I am working with a client computer and a server computer (Raspberry Pi). The Raspberry Pi hosts a MySQL database and an application designed to read RFID tags from the database. This application is written in C# and operates using Mono. Currently, I am i ...

How can I make multiple elements change color when hovering with CSS?

Hey there! I have a little design challenge that I need help with. On my website (), I am trying to make multiple elements of a specific item change color when the user hovers over the text. If you hover over the "more" menu item, you'll notice that o ...

What is the method for including HTML special characters in d3.js?

I am attempting to incorporate the degree symbol in my HTML code using ° const degreeNum = d3 .select(`#windBox${order}`) .append("text") .attr("x", 250) .attr("y", 130) .style("font", "bold 50px sans-serif") ...

Is there a way to identify when a Tween.js animation has completed?

Is there a completed or finished event available when using this code for animating the camera in a scene with tween.js? tween : function (target){ var position = camera.position; var tween = new TWEEN.Tween(p ...

Issue with Internet Explorer: Refusing to run javascript included in AJAX-loaded content

While loading AJAX content that includes a javascript function using the jQuery .load function with done() on completion, I am facing an issue. $('#content').load(a, done); function done() { if(pagejs() == 'function') { ...

Exploring AngularJS and Jasmine: Testing a controller function that interacts with a service via $http

I encountered an issue while testing a controller that relies on a service. The problem arises because the service is currently set to null in order to focus solely on testing the controller. The current test setup is failing due to the BoardService being ...