0

In react application I have json response object that looks like this :

{
   100: "apple,
   200: "bananas",
   300: "pineapples"
 }

I want to get a specific value, for example, a value that corresponds to 200 - "bananas".

What is the easiest way to do this? thank you!

2 Answers 2

2
const yourObject = {
   100: "apple",
   200: "bananas",
   300: "pineapples"
 }

console.log(yourObject[key])
Sign up to request clarification or add additional context in comments.

Comments

1

Assuming your JSON object is saved in myJson

const myJson = {
   100: "apple",
   200: "bananas",
   300: "pineapples"
 }

You would access bananas like that:

myJson[200]

2 Comments

can I ask you here another question related to this topic?
I would suggest opening a new question and I will try to answer that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.