javascript - 如何使用变量从 json 中取出对象?
问题描述
我有一个小问题,我无法理解。
let content = getData() //This will return a json in the variable content
content[0] //This is the output that i want but instead of [0], I want to store this into a variable
let path = "[0]"
content.path //something like that but the good way, can't figure it out how i could do this
谢谢!
解决方案
尝试使用括号表示法,因为这允许动态值作为键名:
let path = "0";
content[path]
推荐阅读
- api - Dell Boomi 将 1 个 api 分解为多个?
- c# - Chrome 驱动程序不适用于 azure Web 应用程序
- signal-processing - 从fft计算频率时如何去除旁瓣?
- c# - 表单加载后表单图标从任务栏中消失
- node.js - 将消息从 AWS Lambda 推送到 Kafka
- encryption - 在 ActiveMQ 中加密 Web 控制台密码
- php - 创建插件域的子域
- initialization - 如何修复“不能在属性初始化器中使用实例成员'textField_1';属性初始化器在'self'可用之前运行”?
- c++ - C++:对于一个继承了多个类的类,如何从一个类继承某些属性而从另一个类继承其他属性?
- angular - 如何以角度显示 Highchart 金字塔内的系列数据标签