[英]How to get value of key in same node level with JSON format
我有这个JSON格式结构
valuesColors : [{
key: "<75%",
color:"61C56E"
},
{
key: ">=75%&<90%",
color:"6144RF"
},
{
key: ">90%",
color:"333RTE"
}
]
例如,我会得到valuesColor.key ==“> 75%”的valuesColors.color。 这里的问题是我在键的相同级别中具有值,所以我不能使用.
您不能使用。 因为您的对象是一个数组类型,并且该数组中的每个元素都是一个json节点。 因此,您需要访问相关的索引,然后才能对该对象进行操作。
let array = [{key: '1'}, {key: '2'}];
let jsonNode = array[0];
console.log(jsonNode.key);
console.log(array[0].key);
console.log(array[1].key);
console.log(array.key); // Will not work as this is an array, not a json object.
const result = valuesColors.find(entry => {
return entry.key == "<75%"; // or what ever logic
});
console.log(result.color); // -> 61C56E
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.