Combining the keys of two objects in JSON

console.log(a) ; // output in console window= 1
console.log(b);// output in console window= 2

var c = {a : b};// Is there a better way to do this?
var d = JSON.stringify(c);
d = encodeURIComponent(d);

I want the final value of d to be {1:2}.

Answer №1

One option is to utilize a computed property

let example = {[key] : value};

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 are some effective strategies for reducing excessive re-rendering of React components?

Here is how I am displaying a list of components on the screen: const MessagesContainer = ({ messages, categories, addHandler }) => { const options = categories.map(category => ( { value: category.name, label: category.name } )); ...

AngularJS - Creating a date input with ng-model that stores the date in milliseconds

Imagine having a number that signifies the time in milliseconds since 1970, like: 1388664300000 and then utilizing: {{ day.date | date: "dd.MM.yyyy" }} it becomes 07.05.2015! Everything seems fine until now. Now, the goal is to input the same data into ...

Unable to detect the click event on Bootstrap accordion

I am currently utilizing Bootstrap to populate a table with data and then attempting to capture an accordion show event. My intention is to extract the div id in order to make an ajax call for more information on the respective item. Unfortunately, I have ...

Unable to load connected modules from npm/yarn link within the WSL environment

Trying to import a local dependency into my project is proving to be quite challenging. The situation at hand involves a project named 'test_project' and another one called 'test_module'. Linking test module to the global node_modules ...

Does JSON have a special reserved key for identifying the time?

I've noticed an interesting issue when logging the json string of a key labeled tid - it always shows up as 0. Take a look at this example: var transaction = {tid:1, type:0, time:126312736}; var transStr = JSON.stringify(transaction); console.log(tra ...

In Node.js, JavaScript, when using SQLite, the variables are inserted as Null

I have spent a lot of time searching and trying various methods, but I am still unable to solve this issue. My goal is to insert 8 variables received from an API call into an SQLite table. Although the execution seems correct, when I query the table, all v ...

Steps for creating an asynchronous Redis subscriber invocation

My current setup involves a Redis server within AWS ElastiCache. I am publishing messages to a Redis channel and attempting to retrieve these messages through subscription using a JavaScript script as shown below: const redis = require("redis"); const sub ...

Error: Running the command 'yarn eg:'live-server'' is not a valid internal or external command

Currently, I am utilizing yarn v1.6.0 to manage dependencies. I have globally installed live-server by running the following command: yarn global-add live-server However, upon executing it as live server, I encounter the following error: 'live-ser ...

Ensure that the page fully loads by using Selenium and PhantomJS during testing of an AngularJS website

After exploring many responses, it appears that the recommended solution is to use Wait for page load in Selenium. While this approach makes sense, my issue persists. I am dealing with a website built using Angular JS and facing challenges while navigating ...

how can I enable pass-through functionality in express middleware?

Currently, I have a POST API endpoint named /users which is used to retrieve the list of users. The reason behind using POST instead of GET is because the request body can be quite large and it may not fit in the URL for a GET request. In this scenario, i ...

Create a stylish navigation dropdown with MaterializeCSS

Incorporating the materializecss dropdown menu feature, I encountered an issue where only two out of four dropdown menu items were visible. Here is the HTML code snippet in question: <nav class="white blue-text"> <div class="navbar-wrapper con ...

Vue.js Interval Functionality Malfunctioning

I'm brand new to Vuejs and I'm attempting to set an interval for a function, but unfortunately it's not working as expected. Instead, I am encountering the following error: Uncaught TypeError: Cannot read property 'unshift' of u ...

best practices for transferring object data to a table with ng-repeat

I have an object called 'SEG-Data with the following structure. I am attempting to display this data in a table using ng-repeat. SEG_Data Object {ImportValues: Array[2]} ImportValues: Array[2] 0: Object ImportArray: "004 ...

Issue with combining an AngularJS template generated from ng-repeat with a custom directive on the same element

Currently, I have implemented an ng-repeat directive on an element to loop through an array in the scope. Additionally, I have a custom directive (used to create a jquery widget) applied to the same element. The issue arises because the custom directive i ...

Assessing the validity of a boolean condition as either true or false while iterating through a for loop

I am facing an issue that involves converting a boolean value to true or false if a string contains the word "unlimited". Additionally, I am adding a subscription to a set of values and need to use *NgIf to control page rendering based on this boolean. &l ...

Dealing with AngularJS ng-model problems when duplicating a form

Currently, I am facing an issue with sending parameters to control and require some guidance. I have multiple types of questions within the ng-repeat loop named 'question' that I am iterating through. The problem arises when there are two questi ...

Key-based user retrieval is unavailable in Express, "findAll" can only be done through email

I've created a straightforward Express/Pug application designed for searching users in a database by "email" or by "key". In this setup, each user is assigned a unique string as their key. The structure of my user model and index model files can be se ...

Is it possible to create multiple text input components using the "each" function, and how can I update the state by combining all of them together?

I am looking to create a text-based word game where the length of each word changes with every level. Each letter will be placed in its own box, forming a matrix (e.g. 10 words, length: 10 => 10x10 matrix). How can I generate multiple text input componen ...

The Express REST API response handling procedures are not being identified

Currently I am facing an issue with a straightforward get request that returns json data while attempting to implement it. Despite following the tutorials for the Express Web Framework REST API, I consistently encounter the same error ERROR: TypeError: r ...

Azure Function: Transfer data from a JSON Webhook to a SQL database

I am currently working on implementing a variation of the following tutorial: However, I encountered an error: An exception occurred while executing the function: Functions.Incoming. System.Net.Http.Formatting: No MediaTypeFormatter is available to rea ...