What is the proper way to extract a JSON value?

I have a JSON array that looks like this:

var currencyformats =
{"USD":[
    {'symbol':'$', 'left':true}
],
    "UAH":[
        {'symbol':'₴', 'left':true}
    ],
    "EUR":[
        {'symbol':'€', 'left':false}
    ]
};

How can I retrieve the symbol '₴'? I attempted to do this (with the cookie "to" set to "UAH")

currencyformats[$.cookie("to")].symbol

but all I got was undefined

Answer №1

The issue lies in the organization of your code where each country code is associated with an array containing only one object. This means that after accessing the country code, you must then access the first item in the array.

Therefore, assuming that the cookie holds the intended value:

currencyformats[$.cookie("to")][0].symbol;

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

How can I display a particular section of my JSON data in an AngularJS application?

Below is an example of a JSON structure: {"years":[ { "year_title":"94", "months":[...] } { "year_title":"95", "months":[...] } { "year_title":"96", "months":[...] } ]} I was able to display the data using the code sni ...

Encircle the text within intersecting divs

I am facing an issue with my main div that contains some text and 2 other overlapping divs. The text in the main div is getting overlapped by the other two divs. I need help to make the text in the main div wrap around the overlapping divs. It may sound s ...

Display information in a detailed table row using JSON formatting

I have set up a table where clicking on a button toggles the details of the corresponding row. However, I am having trouble formatting and sizing the JSON data within the table. Is there a way to achieve this? This is how I implemented it: HTML < ...

Nodemon failing to trigger auto-refresh

My journey with learning node.js using nodemon has hit a roadblock. Despite following tutorials and installing everything exactly as shown, I'm facing an issue. Whenever I enter 'nodemon index.js' in the terminal, it hosts properly but any c ...

How to dynamically generate <select> <option> elements in VueJS using the v-for directive

Just started exploring VueJS and I recently learned how to use a v-for loop to populate a Select Options box. <select> <option v-for="person in persons" :value="personid">{{ personname }}</option> </select> ...

In Three.js r74, JSONLoader mistakenly links a duplicate of all geometry to the initial bone

I have gained more insight into the bug, so I am rewriting this question. It seems that when using the JSONLoader in r74, the first named bone in an exported Maya scene ends up with a duplicate of all the geometry. EDIT: Check out this JSFiddle for refere ...

Tips for interpreting information from a JSON array that has been stringified, looping through the data, and utilizing it effectively

I'm currently exploring Node JS packages and I need some guidance. Here is an example of the JSON data that I have: [{ "name":"SpiderMan", "description":"Superhero", "head_id":"29", "domain_name":"spiderman.com" }] I am trying to figure out how to ...

How can I convert the following into a formatted list of JSON objects, resembling the output from an API request in Python?

The data I currently have is structured like this: ('Domain Name,Start Date,End Date,Attributed To,Tags\r\n' 'domain.com,2011-01-01,Active,Company A SA,\r\n' 'domain.com,2011-01-01,Active,Company A SA,\r& ...

Alert Div from Bootstrap fails to appear during the second ajax request if the first ajax request is canceled

I've implemented a dismissible alert in my HTML file that starts off hidden. Here's the code snippet: <div class="alert alert-dismissible" role="alert" id="msgdiv" style="margin-bottom:5px;display: none;"> <button type="button" clas ...

sending data from a servlet to ajax

Implementing a star-based voting system involves sending an ajax request to update the database through a servlet when a user casts their vote. This is the ajax code used: $.ajax({ type:'GET', contentType: "charset=utf- ...

There was an error during product validation that occurred in the userId field. In the Node.js application, it is required to

I am in the process of developing a small shop application using node.js, express, and mongoose. However, I have encountered an issue when attempting to send data to the MongoDB database via mongoose. Here is the product class I have created: const mongoo ...

Creating a Mongoose schema with a predefined key variable

I am currently utilizing expressjs, mongodb, and mongoose. My goal is to update the counts object within the given schema: var UsersSchema = new Schema({ username: { type: String, required: true }, counts: { followers: { type: Number, default: 0 } ...

Using jQuery to attach events and trigger them

Within my code, I have the following scenarios: $("#searchbar").trigger("onOptionsApplied"); And in another part of the code: $("#searchbar").bind("onOptionsApplied", function () { alert("fdafds"); }); Despite executing the bind() before the trigge ...

Developing a custom styling class using JavaScript

Looking to create a custom style class within JavaScript tags. The class would look something like this: #file-ok { background-image: url(<?php echo json.get('filename'); ?>); } Essentially, the value returned from the PHP file (json ...

Array with multiple dimensions using commas as delimiters

My array (array[]) contains elements in the format below, separated by a comma: array[0] = abc, def, 123, ghi I want to transform this array into another multi-dimensional array (arrayTwo[]), structured like this: arrayTwo[0][0] = "abc" arrayTwo[0][1] = ...

Dynamic navigation experiencing erratic behavior when using display flex

I attempted to enhance my previous projects by converting them into flexbox. However, I ran into an issue where the ul element was displaying as a block. To fix this, I used JavaScript to change it to display flex. Here is the fiddle: // JavaScript co ...

Encountered a STRING instead of an expected BEGIN_OBJECT at the beginning of the JSON file

Having trouble with an error message: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ Any ideas on how to fix this? This is the API end point: @FormUrlEncoded @Headers({"Accept: application/json"}) @POST("/api/regis ...

The current Webpack configuration for production fails to account for importing CSS files

I am struggling to figure out how to properly load a static site that is not located in the root folder: let HWPTest = new HtmlWebpackPlugin({ template: __dirname + "/src/artists/test.html", filename: 'artists/test.html', favicon: &apos ...

Merging two JSON objects in the absence of one

function fetchData(url) { return fetch(url).then(function(response) { return response.json(); }).then(function(jsonData) { return jsonData; }); } try { fetchData(`https://api.hypixel.net/skyblock/auctions?key=${apikey}`).the ...

Initial Row Defense Against Full Screen Websites

I am in the process of creating a webpage that spans 100% width using the foundation framework. Everything is going smoothly until I encounter an issue when trying to include a "div class="row" container. My goal is to have two images side by side, occupy ...