javascript - 从对象/数组中获取值
问题描述
我只需要在 JS 的变量中获取令牌。
{
"user": {
"id": "string",
"nickName": "string",
"score": 0,
"rank": 0
},
"token": "string"
}
这是我保存在变量中的响应,但我只需要从令牌中获取“字符串”值
解决方案
如果您将此响应存储在变量中,例如:
let response = {
"user": {
"id": "string",
"nickName": "string",
"score": 0,
"rank": 0
},
"token": "string"
}
您可以像这样从“令牌”属性中提取值
let tokenFromObject = response.token
或者
let tokenFromObject = response["token"]
或者
let { token } = response
推荐阅读
- swift - 如何在不连接它们的情况下在 MapView 上绘制两个 MKPolygons?
- javascript - 如何使用chart.js在饼图中显示切片内的切片值
- python-3.x - BlockingIOError: WinError 10035 无法立即完成非阻塞套接字操作
- python - 导入 sutime 模块时出现以下导入错误 - 这是什么意思?
- python - 如何让 tkinter 工作(在 vim 中)以及如何让 python-3.x 作为 linux 的默认 python 运行?
- java - Selenium - 将系统日志输出到文本文件
- angular - 同意后如何使用 Angular 加载模块?
- typescript - 使用泛型参数作为文字字段名称创建新类型
- javascript - 为什么不允许此操作
- javascript - 如何向下拉列表添加另一个值