小编Fon*_*nty的帖子

如何 concat() 多个数组并检查值是否已存在

我将多个数组连接到一个数组。这个效果很好

\n\n
this.facetsLocations = [].concat(\n                response.facets[\'134_locations\'].terms,\n                response.facets[\'135_locations\'].terms\n              );\n
Run Code Online (Sandbox Code Playgroud)\n\n

但输出不是我想要的。正如你所看到的,我有相同的术语,如“deutschland”,计数:6\n“deutschland”,计数:4 等等。

\n\n

结果应该是一个“deutschland”,计数 10\ni 想检查该值是否已存在并添加计数值。

\n\n
(11) [{\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}]\n0: {term: "deutschland", count: 6}\n1: {term: "basel", count: 3}\n2: {term: "osteuropa", count: 2}\n3: {term: "\xc3\xb6sterreich", count: 1}\n4: {term: "ungarn", count: 1}\n5: {term: "schweiz", count: 1}\n6: {term: "basel", count: 5}\n7: {term: "deutschland", count: 4}\n8: {term: "\xc3\xb6sterreich", count: 1}\n9: {term: "ungarn", count: 1}\n
Run Code Online (Sandbox Code Playgroud)\n

arrays typescript angular

0
推荐指数
1
解决办法
4287
查看次数

标签 统计

angular ×1

arrays ×1

typescript ×1