计算Javascript中数字数组的出现次数

时间:2018-02-12 15:58:04

标签: javascript arrays object compare

如何计算普通Javascript中数字数组的出现次数?这样的事情(想象这些数字集有数百个):

[2, 5, 66, 199]
[32, 56, 88, 109]
[13, 45, 102, 200]
[2, 5, 66, 199]
[2, 5, 66, 199]
[32, 56, 88, 109]

会给我这样的东西:

2, 5, 66, 199 -> 3 times
32, 56, 88, 109 -> 2 times
13, 45, 102, 200 -> 1 time

1 个答案:

答案 0 :(得分:4)

从数组创建字符串并将其用作对象中的键。如果您希望<httpTransport manualAddressing="false" allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" proxyAuthenticationScheme="Anonymous" realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true" /> [1, 2] != [2, 1]方法之前删除sort

join