How to retrieve the values of a property from a JavaScript object

Looking for a fresh perspective on this issue. I'm currently retrieving historical data from the cryptocompare API, but I'm having trouble accessing the received values.

https://i.sstatic.net/oH6hz.png

When I hardcode it as res.data.OMG.USD, I can retrieve the desired result.

This is the exact format in which the data is returned. I've attempted to parse it into a string and store the results in an array, but I still can't access the prices. When I used Object.keys, it only returned the name and not the USD or EUR values. What could be the issue here?

UPDATE: Here's the request; I'm attempting to retrieve the USD values.

 $http.get(
        'data/pricehistorical?fsym=BTC&tsyms=USD,EUR'
          ).then(
            function(res) {
           //sample response
          /*

          {"OMG":{"USD":8.19,"EUR":6.65}}
          {"BTC":{"USD":10226.86,"EUR":8153.29}}
          */
     },

  function(res) {
        console.log(res);
      }
    );

Answer №1

To begin with, it is important to grasp the concept of the JSON format.

If you have already familiarized yourself with it, you can proceed by writing JavaScript code:

var sampleData = {"Wow": {"CAD": 10.55, "GBP": 8.21}};

//You can then retrieve CAD by

console.log(sampleData.Wow.CAD);

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

A dynamic substitute for the Supersized slideshow option

I am in the process of updating my website and the final task on my to-do list is to replace the Supersized plugin with a more suitable alternative. The website is constructed using WordPress and I am utilizing jQuery. My goal is to find a fullscreen slid ...

What is the correct way to convert a JArray into a list of strings?

I have a JArray saved in a variable of type object public object Errors { get; } This variable can store either of the following: Errors = {[ { "name": [ "Username "admin" has already been taken." ], ...

``There seems to be an issue with the functionality of Passport.js' multiple login system

I'm encountering a strange issue with my login system. Everything seems to be working fine, including local login, Google login, and Facebook login. However, the problem arises when I attempt to register with Google after already registering with Face ...

In Typescript, convert an object into a different type while maintaining its keys in the resulting type

Imagine you have a code snippet like this type ResourceDecorator = (input: UserResourceDefinition) => DecoratedResourceDefinition const decorate: ResourceDecorator = ... const resources = decorate({ Book1: { resourceName: 'my-book', ...

Kendo-UI grid and AngularJS integration issue: Calculated field not refreshing

I am currently working with a kendo-ui grid that displays order lines featuring columns such as Qty, Price, and Total. The Total column is calculated by multiplying the quantity by the price (Qty x Price). For editing purposes, I have implemented a custom ...

Executing a function from another module (File) within a React JS application

I am currently utilizing the Material UI v1.0.0-beta.33 in my project, which includes an App Bar component. import React from "react"; import PropTypes from "prop-types"; import { withStyles } from "material-ui/styles"; import AppBar from "material-ui/App ...

Is there a way to access hover effect information in Atom editor similar to how it appears in VScode?

Is there a specific plugin required in Atom to display information when hovering over variables, objects, or functions similar to intellisense? VSCode does this automatically, but I am looking for the same functionality in Atom. https://i.stack.imgur.com/ ...

Establishing a small boutique utilizing Vue.observable for property getters

I am currently importing the createStore function into a store.js file and passing an object with state properties and mutation functions as an argument, which is working well. createStore.js import Vue from 'vue' function createStore({ state, ...

Is Spring MVC in partnership with AngularJS a winning combination?

Currently, I have been working on two separate projects using Spring MVC, Thymeleaf, HTML, Bootstrap, and a sprinkle of vanilla JS/jQuery. Despite that, my experience with AngularJS is limited. I'm wondering if it would be beneficial to embark on a ...

Unable to access a frame inside an iframe and frameset using JavaScript when both domains are identical

I am attempting to use JavaScript to access an HTML element within a nested frame in an iframe and frameset. The structure of the HTML is as follows: <iframe id="central_iframe" name="central_iframe" (...)> <frameset cols="185, *" border="0" ...

Using Spry Validate for form validation in conjunction with Ajax submission

I'm currently facing an issue where I want my form to validate before the ajax call is made, but I can't seem to figure out the correct coding for this process. When I separate them, I am able to either post using ajax without validation or with ...

Using identical variable names for functions in Node.js

I'm feeling a bit puzzled about the following code snippet. Is it possible to create a class in JavaScript like this? module.exports = function testName(params){ testName.test = function(req, res){ //some code here } return testName; } Inste ...

Display a featherlightbox popup when the page loads

Well, here's the deal. I don't have any experience with wordpress php coding at all, but I can make basic adjustments using the wordpress admin. Now I've run into an issue. I tried to use the feather lightbox js, and below is a snippet of co ...

Exploring the Power of jQuery Deferreds and Promises through Multiple getJSON Requests

I'm currently exploring the concept of jquery deferred/promises. I have a decent grasp on how to handle one ajax call, but I'm struggling with managing multiple ajax calls simultaneously. Here is a link to a jsfiddle showcasing my attempt: http:/ ...

A guide on accessing a dynamic object key in array.map()

How can I dynamically return an object key in array.map()? Currently, I am retrieving the maximum value from an array using a specific object key with the following code: Math.max.apply(Math, class.map(function (o) { return o.Students; })); In this code ...

jQuery: Function is not running as expected

I'm facing a challenge in executing a function twice, and I'm having trouble identifying the issue. Check out my JSFiddle at the following link: http://jsfiddle.net/g6PLu/3/ Javascript function truncate() { $(this).addClass('closed&apo ...

Determine if the server is operational using Microsoft Edge

To verify the status of my server, I have implemented the code below: <head> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script> function checkServerStatus() { var img = document. ...

Immense trade adhesive navigation bar menu

Currently, I am in the process of enhancing a big commerce website and aiming to implement a sticky menu on scroll. I attempted to use bootstrap along with CSS to achieve this functionality, however, encountered some issues. Below is the snippet of code I ...

Can you verify the standard behavior when importing index.js using create-react-app?

I'm trying to wrap my head around why, when using create react app, if a folder contains an index.js file and you want to import it, you only need to specify the folder name. I've been wondering where this default behavior is configured to autom ...

Using Angular to make a DELETE request using HttpClient with a Json Server

My goal is to remove one employee at a time from the Employees list. The Observable is configured in employee.service.ts and subscribed in app.component.ts. However, there seems to be an issue connecting the id of the employee with the removeUser(id) metho ...