Is there an issue with the JavaScript Mapping provided?

const assetMap = {
  General: {
    name: 'Common',
    bkgHex: '#eee',
    fontHex: '#aaa',
  },
 ...

const getAsset = (name, type) => {
  return assetMap.name.type;
}

console.log( getAsset('General', 'name') );

An error occurred:

Uncaught TypeError: Cannot read property 'type' of undefined

Answer №1

To retrieve the values associated with the keys name and type, make sure to use bracket notation like this:

return myAssets[name][type];

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

The data is being retrieved accurately, but unfortunately, it is not showing up correctly when displayed

Currently facing an issue with displaying returned data in a p and textarea element. The function I'm utilizing successfully fetches each key from the comments node and retrieves the comment title and message as expected... function loadComments() { ...

Can a single input slider be used to modify several values at once?

Is there a way to adjust multiple values with just one input slider? I've attempted to do so several times without success. My goal is to modify the value of 50,000 at the top of the slider as well as the value of 250k in the unique view's contai ...

Angular JS Tab Application: A Unique Way to Organize

I am in the process of developing an AngularJS application that includes tabs and dynamic content corresponding to each tab. My goal is to retrieve the content from a JSON file structured as follows: [ { "title": "Hello", "text": "Hi, my name is ...

Step-by-step guide on extracting checkbox value from response in Angular JS

Successfully added a checkbox value to the database. An issue arises when checking a checkbox after receiving a response, as the checked value displays as -1 instead of 0, 1, or 2. When clicking on a checked box, its index value should change to -1, bu ...

The success:function() is not being triggered in the Ajax response with jQuery version 1.8.3

My code is not calling success:function() in the Ajax response when using jQuery 1.8.3, but it works perfectly with jQuery 1.4.2. Here is the code snippet: <script type="text/javascript"> $(document).ready(function(){ $("#usn").on('keyup&a ...

Set up a directory alias for the Grunt connect server

I have a set of folders in my project directory that I would like to make accessible using the Connect framework through a Grunt task. The structure of my folders is as follows... / /src index.jade /styles main.css /dist index.html /docs index.htm ...

Automatically include the date as a column heading along with name and ID

I recently came across a guide on how to dynamically add dates as column headers in a table. However, I encountered an issue where I couldn't add new columns for 'Name', 'Age', and 'Section' before the dynamically generat ...

New data row successfully added to HTML table, revealing an object display

When I click a button, a dialog box opens up. I can fill out the form inside the dialog box and submit it to insert a row into a table. After submitting the form, the newly inserted row displays as [object Object] immediately after submission: https://i.s ...

Tips for displaying a div briefly before loading the second page

Incorporating a div named ADD, I aim to successfully load a second page within the current one using ajaxload. The challenge lies in displaying a div for 4 seconds before loading the second page. How can this be achieved? Following the wait period, the sec ...

Rendering Single File Components with Render Functions in Vue 2: A Step-by-Step Guide

I am facing an issue with rendering a Single File Vue Component using a render function. I have tried different variations like the one below: // simple.vue <template> ... </template> <script> ... </script> // parent.vue <scr ...

I keep encountering an error with the Next.js Image component, even though I have properly included the src prop

By passing the src prop to the UserCard component, I am encountering the following error message. Error Unhandled Runtime Error Error: Image is missing required "src" property. Make sure you pass "src" in props to the `next/image` comp ...

Error message: "Issue encountered with locating Node import module while operating within a docker

I've created a React app along with a Node.js server that includes the following imports: import express from 'express' import compression from 'compression' import cookieParser from 'cookie-parser' import bodyParser from ...

Identification of absence of file selected in input file control

Imagine a scenario where I need to select an image to display on the screen from a select control. If the desired image is not available, I want to be able to choose it from the disk and add this option to the select control while automatically selecting i ...

Utilizing Array.from with a XPathResult: A Comprehensive Guide

In my sample document, I found 138 nodes with the tag td using querySelectorAll. Array.from(document.querySelectorAll('td')).length 138 However, when I tried to do the same using XPath, I did not get any result: Array.from(document.evaluate(". ...

Receiving a "Bad Request" error when trying to access a website

Every time I attempt to call a lengthy URL, I encounter a Bad Request issue. https://localhost:44320/RespostaEmail/96635/750396/[%7B%22IdItem%22:8,%22IdTipoReposta%22:80%7D,%7B%22IdItem%22:1,%22IdTipoReposta%22:80%7D,%7B%22IdItem%22:3,%22IdTipoReposta%22:8 ...

Retrieve an item from a mapped array

Currently, I am using the following code snippet console.log('errors: ' + password.get('errors')); to check the output from password.get('errors'));, and in the console, the response is as follows: List [ Map { "id": "validat ...

Clicking a button to escape an iframe and navigate to a new URL within the same domain

What is the proper JavaScript syntax for breaking out of an iframe and redirecting to a different URL within the same domain? I have a page inside an iframe with a form, and once that form is submitted, I want to open a separate page on the site in the p ...

Submitting information retrieved through an AJAX request to a MySQL database using PHP

I have implemented a JavaScript function to collect and display data, but now I am looking to save this data into a MySQL database for tracking purposes. I attempted to connect to the MySQL database locally using PHP code, but encountered some issues. I be ...

Choosing the date and time using the picker with the type of 'datetime-local'

Is there a way to ensure that the start date/time is always earlier than the end date/time when selecting them using two text-field HTML elements? <v-text-field id="setTime" outlined type="datetime-local" label="Start ...

Stopping a jQuery AJAX request when the user switches to a different page

A method has been defined for sending a jQuery AJAX request as shown below: sendAjaxRequest(URL, data) { return $.ajax({ type : 'POST', url : URL, crossDomain : true, data : JSON.stringif ...