-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
  • 187,200
  • 47
  • 362
  • 445
Mubarak A
  • 15
  • 3

2 Answers2

1

You should use this:

var col = 'A101';
var value=sampleJson[0][col]
Manwal
  • 23,450
  • 12
  • 63
  • 93
0

You can use a string with A101 and square brackets.

var col="A101";
var value=sampleJson[0][col];
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445