typescript - 为什么数组的长度属性计算打字稿中的字符数?
问题描述
我创建了一个数组并在其中存储字符串,但是当我使用数组中只有一个元素的 .length 属性时,它会计算字符串的长度。如果元素不止一个,它会像往常一样计算元素。
private organizationArray: Array<string>;
const claims = jwtDecode<any>(token);
this.claims = {
email: claims['http://schemas.xmlsoap.org/ws/***/**/***/claims/emailaddress'],
id: claims['http://schemas.xmlsoap.org/ws/***/**/*****/claims/sid'],
name: claims['http://schemas.xmlsoap.org/ws/***/**/****/claims/name'],
expires: new Date(claims['exp'] * 1000),
};
this.organizationArray = claims['http://schemas.*****.**/**/****/**/*******/claims/organization'];
console.log( this.organizationArray.length)
这里我在数组中有 3 个元素:
CONSOLE LOG file:///app/app/services/jwt.service.js:55:20: 3
这里我在数组中有 1 个元素,包含 84 个字符:
CONSOLE LOG file:///app/app/services/jwt.service.js:55:20: 84
索赔退货
{"Id":"********-0000-0000-0000-********","Name":"NAME","AccessibleAreas":**},{"Id":"******-****-*****-****-******","Name":"Demo Inc.","AccessibleAreas":*}
解决方案
推荐阅读
- function - 如何正确地将 Win32 类对象传递给函数
- firebase - 添加 Firestore 依赖项会导致 Flutter 应用程序出错
- c# - Unity:如何递归找到所有邻居(邻居的邻居)?
- sql-server - 为什么光标没有终止?
- php - 将 MySQL 数据读入 Bootstrap 4 列
- node.js - 添加代理以响应 package.json 后,不断收到“代理错误:无法代理请求”错误
- java - 如何唤醒不同实例的线程?
- python-3.x - 启动器中的致命错误:无法使用“c:\ci\spyder_1563210361503\_h_env\pythonw.exe”“D:\anaconda3.7\Scripts\spyder3.exe”创建进程
- python - 使用 django-filter 库和 CBV 进行分页
- javascript - 在 React Native 中创建时间线