首页 > 解决方案 > 为什么数组的长度属性计算打字稿中的字符数?

问题描述

我创建了一个数组并在其中存储字符串,但是当我使用数组中只有一个元素的 .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":*}

标签: typescript

解决方案


推荐阅读