Javascript: Proper syntax with arrays?
Accessing an array element with the following line works 开发者_如何学编程great;
if (dataset[i].properties.property == "value") { ...
However when I want to make it a tad more dynamic, I get stuck. How can I use my own variable to access the array element, as shown below?
var myVar = 'property';
if (dataset[i].properties.myVar == "value") { ...
Thanks
Use dataset[i].properties[myVar] == 'value'
.
精彩评论