angularjs - 如何从数组中过滤和计算 Typescript 中的项目
问题描述
我想从数组中过滤和计算 Typescript 中的项目。
我尝试了下面的代码给我这个结果:AA,BB,AA,CC
const types = cars.map((car) => car.type);
const cars = [
{
id: 2,
brand: "Opel",
type: "AA",
},
{
id: 8,
brand: "Toyota",
type: "BB",
},
{
id: 40,
brand: "Opel",
type: "AA",
},
{
id: 66,
brand: "BMW",
type: "CC",
}
];
我想像下面这样按类型计数和排序,我该如何在 Typescript 中做到这一点?
2AA、1BB、1CC
解决方案
推荐阅读
- ruby-on-rails - Bootstrap 5 & Rails:带有左中右内容的标题菜单,奇怪的行为
- tfs - Azure DevOps 安全文件指南
- powershell - 创建 PowerShell 别名时,无法将类型“System.String”的“节点”值转换为类型“System.Diagnostics.Process”
- python-3.x - Python Combobox 值在绑定后未过滤
- asp.net-core - 谁能解释为什么 Razor 调用 InvokeAsync 但该类实现 Invoke
- apache-kafka - 参数不匹配;org.joda.time.Instant 无法转换为 org.apache.beam.sdk.transforms.SerializableFunction
- r - 闪亮的书签无法恢复 selectizeinput
- sql - 在 Apex IG 中使用案例条件的 Oracle SQL 减去列
- python - 我们如何在请求中使用代理连接到 dns 服务器?
- typescript - Jest with ES6 and Typescript