I have a JSON array as follows:
var testJSON = [
{ "AssetA": "asset_a", "AssetB": "asset_b" },
{ "AssetA": "asset_a", "AssetB": "asset_b" },
{ "AssetA": "asset_c", "AssetB": "asset_d" },
{ "AssetA": "asset_c", "AssetB": "asset_e" }];
What I'd like to do is count all the duplicates. For example, I'd like my result to be another array, where the first two elements of the row are are the repeating values, and the third element is the number of times it repeats like so:
[{asset_a, asset_b,2},
{asset_c, asset_d,1},
{asset_c, asset_e,1}]
Here is what I have so far to be able to identify the duplicates, but it keeps getting hung up and my visual studio crashes:
for (var i = 0; i < testJSON.length; i++) {
for (var j = i + 1; j < testJSON.length;) {
if (testJSON[i][0] == testJSON[j][0] && testJSON[i][1] == testJSON[j][1])
// Found the same. Remove it.
console.log("they are equal");
else
// No match. Go ahead.
j++;
}
}
jin theifbranch, so the inner loop never ends.j++when the elements are not equal?