What is the best way to manage two state variables simultaneously in React Native?

Looking to retrieve JSON data using 2 state variables. Consider the following JSON object:

{
  "user1":
    {"age":32, 
     "role_name":"editor"
    },
  "user2":
    {"age":42,
     "role_name":"moderator"
    }
}

The variables are as follows:
var1: "user1"
var2: "age"
The desired access format is:

jsonobj.this.state.var1.this.state.var2

Attempted code:

jsonobj.(this.state.var1).(this.state.var2)

jsonobj.{this.state.var1}.{this.state.var2}

Unfortunately, neither of them yielded the desired outcome.

Answer №1

attempt using this.state.var1[this.state.var2]

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 Three.js scene features an Obj and Cubemap, but encountered an issue with THbindTexture where textures cannot be utilized with multiple targets

Attempting to craft a three.js scene featuring a cubemap panorama background and various .obj files with .mtl textures situated within the scene, an intriguing WebGL error has surfaced. The specific issue being encountered reads: THbindTexture: textures c ...

When attempting to make an HTTP POST request from an Android device to a PHP server,

After attempting multiple tutorials on the internet, I am struggling to successfully make a simple HTTPRequest to a PHP script for user registration. The code I have tried is resulting in a NullPointerException when using HTTP POST and showing null values ...

Exploring the Matrix Filter Functionality in JavaScript

After successfully setting up CSS rotation for all browsers, I am now looking to achieve the same effect using JavaScript. jQuery is also being utilized in this process with the following code snippet: .css({ '-ms-filter':"progid:DXImageTransfor ...

Performing unit testing on two services that reside in separate modules using the Jasmine testing framework

I have developed a service in Angular and you can view it on this PLUNKER. In the RouteService, I am injecting CommonService, $rootRouter, ModalService. Please note the following module structure : CommonService belongs to mysampleapp.core RouteS ...

When making an ajax call, I passed the data "itemShape" but on the URL page, an error appeared stating "Undefined index: itemShape"

Hello, I have been using an Ajax function to send data with the key itemShape. However, when I directly access the URL page or service page, it displays the following error: Notice: Undefined index: itemShape in C:\wamp64\www\inventory_so ...

Arrange an array of objects to a specific sequence

I am currently working with an array of objects that contain a property named 'CODE'. [ { ID: 168, NAME: "First name", CODE: "AD" }, { ID: 167, NAME: "Second name", CODE: "CC" }, { ID: 169, NAME: "Third name", ...

What sets apart gzip from x-gzip content? And how can I decompress x-gzip specifically? zlib appears to be struggling

One of my npm libraries, named "by-request", has the ability to auto-decompress web content. A snippet of code from this library that handles auto-decompression is shown below: if (!options.dontDecompress || !binary) { if (contentEncoding ...

Tips for arranging elements in proper order following a rotation

Having trouble aligning rotated divs? Let's say we rotate .straight by 30deg, and now we want to find the new offset coordinates of its bottom right corner. This way, we can perfectly match up the bottom left corners of .curve with this new coordinate ...

Problem: The variable "$" is not defined in angular datatables causing a ReferenceError

Trying to implement Paging and sorting in my table, but encountered an error even after following all the steps mentioned here: . Tried troubleshooting the issue with no success. Ensured that all dependencies were installed properly. Below is the compo ...

Sinon - a spy that can intercept *all* property accesses on an object

I have a function that looks something like this: import {someLibraryMethod} from 'someLibrary'; function setFullWidth(el) { someLibraryMethod(el); el.setAttribute('width', '100%'); } To test this function, I am utilizi ...

Safari was unable to load the webpage due to a lack of response from the server

One of the pages on my ASP.NET website is experiencing slow loading times. While it works fine on all Android and MAC operating systems, as well as on iOS versions except for 10.0.0.2 with Safari browser. When attempting to load the page on Safari in ...

Converting ArrayList elements into JSON objects in Android: A simple guide

I am trying to convert items from two array lists into JSON objects and then add those JSON objects back to an array list. However, I am encountering a problem where only the last element of the array list is being converted into JSON objects. JSON Object ...

What is the process of embedding a string with pug code into a pug file?

How can I interpolate a string with pug formatted code in a pug file? Here is what I have tried: - var text = "i.home.icon" div= text div !{text} div #{text} div ${${text}} div {{text}} div {text} div \#{text} div \{text} div ${text} div # ...

Is it possible to achieve a fade effect in material-ui that truly hides the component instead of just disabling its visibility? If so, how can this be accomplished?

Currently, I am utilizing the component provided by material-ui, which can be found at material-ui. <Fade in={!randomizeFlag}> <Grid> <FormControlLabel control={<Switch onChange={this.handleStartValueFlag} & ...

What is the process for incorporating a package.json file into a completed React application?

When using the npm build command to build a react app for production environment, we get a build folder containing html, css, and JavaScript files, but the package.json file is missing. If we try to use this file to set an http proxy endpoint for connecti ...

Building web applications using static HTML combined with the Vue.js framework and Bootstrap-V

Currently, I am developing a PHP Laravel web page that consists of numerous static HTML pages. However, there are certain sections where I need to implement a Single Page Application (SPA). I am reluctant to opt for server-side rendering or switch entirely ...

angular: handling duplicates in ng-repeat

Here is the JSON data: streams = [{ id: 0, codec_type: 'video', content: '1920x1040 - H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10' }, { id: 1, codec_type: 'audio', content: '5.1(side) - cze - undefined' }, ...

Can anyone suggest a method to set up a group chat without the need for a database?

I am interested in setting up a group chat where all messages and corresponding usernames are stored in a JSON file. However, achieving this without the use of node.js or MySQLi seems to be quite challenging. Currently, I am able to read the JSON file an ...

Ways to extract pertinent information from a PHP API

I've been attempting to add parameters to my query, but I keep getting inconsistent results. Despite trying different methods, I haven't been successful. Take a look at the code below. First, here is my code that functions properly without using ...

Filter an array using regular expressions in JavaScript

Currently, I am facing a challenge in creating a new array of strings by filtering another array for a specific pattern. For example: let originalString = "4162416245/OG74656489/OG465477378/NW4124124124/NW41246654" I believe this pattern can be ...