开发者

Javascript: Proper syntax with arrays?

开发者 https://www.devze.com 2023-01-30 18:37 出处:网络
Accessing an array element with the following line works 开发者_如何学编程great; if (dataset[i].properties.property == \"value\") { ...

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'.

0

精彩评论

暂无评论...
验证码 换一张
取 消