-3

I have Json like

var sampleJson=[{
A101:20000
}];

while get the value from json in java script

var col=A101;
var value=sampleJson[0].col

here col variable have value A101

that i need to replace here in below line

var value=sampleJson[0].col

how to get value after this .operator..?

Daniel A. White
  • 181,601
  • 45
  • 354
  • 430
Mubarak A
  • 15
  • 3

2 Answers2

1

You should use this:

var col = 'A101';
var value=sampleJson[0][col]
Manwal
  • 22,994
  • 11
  • 59
  • 91
0

You can use a string with A101 and square brackets.

var col="A101";
var value=sampleJson[0][col];
Daniel A. White
  • 181,601
  • 45
  • 354
  • 430