What is the best method for showing the price from this list of items?

{"item":{"icon":"ANOTHER LINK","icon_large":"ANOTHER LINK","id":385,"type":"Default","typeIcon":"ANOTHER LINK","name":"Shark","description":"I should be cautious when consuming this.","current":{"trend":"neutral","price":"1,239"},"today":{"trend":"positive","price":"+15"},"members":"true","day30":{"trend":"positive","change":"+3.0%"},"day90":{"trend":"positive","change":"+52.0%"},"day180":{"trend":"positive","change":"+37.0%"}}}

I am attempting to interpret this json array using Javascript.

if(message.toLowerCase().substring(0,5) == "!item") {
    var item = message.substring(6,message.length)
    var index = 0;
    var found;
    var entry;
    for (index = 0; index < config.length; ++index) {
        entry = config[index];
        if (entry.name == item) {

        var request = require('request');
        var url = "ANOTHER LINK"+ entry.id
request(url, function (error, response, body) {
    if (!error && response.statusCode == 200) {
        var gestat = JSON.parse(body);
        console.log(gestat.item[6].price);
    } else {
        console.log("Received an error: ", error, ", status code: ", response.statusCode);
    }
});
        if (index > index.length) {
            client.action(channel,"This item does not exist!")
        }
        }
    }
}

});

I am trying to retrieve the price but each time I do

console.log(gestat.item[6].price);

The console shows undefined.

Answer №1

Based on the context, it appears that the provided code snippet is the correct response.

 console.log(getstat["item"]["current"]["price"])

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

What is the process for invoking a NodeJS script within a personalized VSCode Extension?

Recently, I created a NodeJS script for one of my projects and now I'm looking to develop a VSCode extension around it. How can I integrate this script as a command within my custom extension? The goal is to have the script packaged along with the e ...

Is there a secure way to prevent user input from causing issues in a BigQuery node insert? Can the BigQuery.insert node library support parameterized queries for added security

I am seeking advice on how to securely insert user form data into BigQuery using the Google Cloud BigQuery library. Specifically, I am curious about the most effective methods for sanitizing, escaping, and cleaning the input data. Is it feasible to implem ...

Restrict results according to values post-merge activity - MongoDB

In my database, I have two collections structured as follows: Collection 1 { "_id": "col1id1", "name": "col1doc1", "properties": [ "<_id1>", "<_id2>", "<_id3>"] } Collection 2 { "_id": "<_id1>", "name": "doc1 ...

Explanation of JavaScript code snippet

fnTest = /abc/.test(function () { abc; }) ? /\bchild\b/ : /.*/; I am struggling to comprehend the functionality of this particular javascript snippet. Would someone be able to elaborate on the logic behind this code fragment? ...

I'm curious, is there a maximum limit for numeric array keys in PHP

I've encountered an issue with arrays in PHP where the keys are being unexpectedly changed. In the example below, I start with a string but somehow it's getting converted to an integer and altering the key when added to another array. Code ----- ...

What is the best way to transmit data via $router.push in Vue.js?

I am currently working on implementing an alert component for a CRUD application using Vue.js. My goal is to pass a message to another component once data has been successfully saved. I attempted to achieve this by passing the data through $router.push lik ...

Steps for Building and Exporting a Next.js Project Without Minification and Optimization

Is there a way to build and export a Next.js project without minifying and optimizing the output files? ...

What is the reason that the <script> tag cannot be directly inserted into the .html() method?

As I continue to learn front-end development, I've created my own version of JS Bin. When the 'run' button is clicked, a statement is executed to showcase the HTML, CSS, and JavaScript in an iframe (the output window): ("iframe").contents() ...

Attempting to sort through elements in JavaScript

I'm looking to filter specific films based on choices made in the dropdown menus below. <select id="filmDropdown"> <option value="0">All Films</option> <option value="1">Film 1</option> <option ...

Transmit information using $broadcast when a button is clicked, and retrieve that information using $scope.$on

I am trying to create a function that will broadcast data from the server upon button click, and then navigate to a new route using $state.go('new-route'). In the controller of this new state, I want to retrieve the transmitted data. However, whe ...

Navigating Paths in Real-time with Javascript - Node.js

When working with PHP, dynamic routing can be achieved by defining classes and methods like: class Route { public function homePage () { echo 'You are on the home page' } public function otherPage () { echo 'You are on so ...

Which option is more beneficial for intercepting API data in Angular 6: interfaces or classes?

My API returns JSON data that is not structured the way I need it, so I have to make changes. { "@odata.context":"xxxxxx", "id":"xxxxxxxx", "businessPhones":[ ], "displayName":"name", "givenName":"pseudo", "jobTitle":null, "ma ...

Stop the stream coming from getUserMedia

After successfully channeling the stream from getUserMedia to a <video> element on the HTML page, I am able to view the video in that element. However, I have encountered an issue where if I pause the video using the controls on the video element a ...

The canvas is unable to render the image from the sprite sheet

I successfully drew an image representing the player, but now I'm encountering difficulties in drawing an enemy character. Despite adding alerts indicating that the program is executing the draw enemy function, the enemy character still doesn't a ...

Javascript Error: Page reload interrupted by Broken Pipe IOError [Errno 32]

I am facing an issue with my javascript function that sends a signal to my flask app for recalculating figures using ajax. Upon successful figure production, I want to reload the page with updated figures by adding a version number to the filename (using & ...

Discovering the method to extract a specific section from a lengthy string

Looking to extract phone numbers from an HTML source code using PHP? Each phone number in the code starts with 'phone=' and ends with %. For example, consider the following sample HTML code: b2e1d163b0b4dc6ebfa5&amp;t=s&amp;phone=9535503 ...

What is the best way to update the color of a label in a Mantine component?

When using the Mantine library, defining a checkbox is done like this: <Checkbox value="react" label="React"/> While it's possible to change the color of the checkbox itself, figuring out how to change the color of the label ...

Embed a local page into an HTML file using PhoneGap

I attempted to load a page within my phonegap application using Jquery .load(), but it isn't functioning because it's on a local machine rather than a server. When I eventually upload the app to PhoneGap Build, my page will still be located in th ...

Display or conceal a <div> segment based on the drop down selection made

A dropdown menu controls the visibility of certain div elements based on the selection made. While this functionality is working for one dropdown, it's not working for another even though the code is very similar. I've tried various solutions but ...

__specification for adding an image to SharePoint using an API

Is there a specific json syntax that can be used to upload an image to SharePoint? I see here how a hyperlinkcan be sent, but I am looking for the equivalent syntax for an image. JSON syntax for pushing hyperlink to SharePoint ...