解析 Json 数组内的 Json 数组并提取唯一值

Parsing Json array inside Json array and extracting unique values

我正在使用 API 返回 JSON 响应,如下所示。

[
  [
    "Tab",
    "Service 1",
    172
  ],
  [
    "Admin",
    "Service 2",
    159
  ],
  [
    "Admin",
    "Service 3",
    5
  ],
  [
    "Admin",
    "Service 4",
    5
  ],
  [
    "Alerts",
    "Service 2",
    159
  ],
  [
    "Summary",
    "Service 1",
    99
  ],
  [
    "Import",
    "Service 2",
    71
  ],
  [
    "Covered",
    "Service 2",
    63
  ],
  [
    "Settings",
    "Service 2",
    53
  ],
  [
    "Application Config",
    "Service 2",
    51
  ]
]

我需要从 javascript 中的此列表中获取独特的服务。 预期响应:

["Service 1", "Service 2", "Service 3", "Service 4"]

我怎样才能做到这一点?我尝试使用 underscorejs.org/#uniq,但没有帮助我。有人可以帮忙吗?

一种方法是在 return 数组上使用 map 来获取您感兴趣的值,然后获取其中的唯一值。

let uniqueServices = _.uniq(apiResponse.map(r => r[1]))