我已经查看了this个,但它没有返回预期的结果,即:

[
  [4, "frente", 196],
  [5, "frente", 196]  
]

function getUniqueData(arr = [
  [4, "frente", 196],
  [4, "frente", 196],
  [5, "frente", 196]  
], uniqueCols = [0]) {
  const uniqueData = arr.filter((currentRow, i) => {
    const currentCombo = uniqueCols.map(index => currentRow[index]);
    return !arr.some((row, j) => {
      const combo = uniqueCols.map(index => row[index]);
      return combo.every((c1, k) => c1 === currentCombo[k]) && i !== j;
    });
  });
  return uniqueData;
}
console.log(getUniqueData())

推荐答案

From what I understand you are trying to remove duplicates. What you have tried removes all the entries that have the same column.
Here is an answer based on a similar thing but for objects

Here I filter out entries based on unique column combinations
Hope this was what you meant

function getUniqueData(arr = [
  [4, "frente", 196],
  [4, "frente", 196],
  [5, "frente", 196]  
], uniqueCols = [0]) {
  const uniqueData = arr.filter((currentRow, i, self) => {
    return i === self.findIndex((t) => {
        return uniqueCols.every((col) => t[col] === currentRow[col])
    })
  });
  return uniqueData;
}
console.log(getUniqueData())

更多 case

function getUniqueData(arr = [
  [4, "frente", 196],
  [4, "frente", 196],
  [5, "frente", 196]  
], uniqueCols = [1]) {
  const uniqueData = arr.filter((currentRow, i, self) => {
    return i === self.findIndex((t) => {
        return uniqueCols.every((col) => t[col] === currentRow[col])
    })
  });
  return uniqueData;
}
console.log(getUniqueData())

function getUniqueData(arr = [
  [4, "a", 196],
  [4, "frente", 196],
  [5, "frente", 196]  
], uniqueCols = [1]) {
  const uniqueData = arr.filter((currentRow, i, self) => {
    return i === self.findIndex((t) => {
        return uniqueCols.every((col) => t[col] === currentRow[col])
    })
  });
  return uniqueData;
}
console.log(getUniqueData())

function getUniqueData(arr = [
  [4, "frente", 196],
  [4, "frente", 196],
  [5, "frente", 196]  
], uniqueCols = [0,1]) {
  const uniqueData = arr.filter((currentRow, i, self) => {
    return i === self.findIndex((t) => {
        return uniqueCols.every((col) => t[col] === currentRow[col])
    })
  });
  return uniqueData;
}
console.log(getUniqueData())

Javascript相关问答推荐

使用useup时,React-Redux无法找到Redux上下文值

我应该在redux reducer中调用其他reducer函数吗?

为什么我的includes声明需要整个字符串?

Cookie中未保存会话数据

Exceljs:我们在file.xlsx(...)&#中发现了一个问题'"" 39人;

Mongoose post hook在使用await保存时不返回Postman响应

将本机导航路由react 到导航栏中未列出的屏幕?

为什么Mutations 观察器用微任务队列而不是macrotask队列处理?

使用原型判断对象是否为类的实例

使用POST请求时,Req.Body为空

如何在JAVASCRIPT中合并两组对象并返回一些键

使用类型:assets资源 /资源&时,webpack的配置对象&无效

如果没有页面重新加载Angular ,innerHTML属性绑定不会更新

try 将Redux工具包与MUI ToggleButtonGroup组件一起使用时出错

删除元素属性或样式属性的首选方法

为什么延迟在我的laravel项目中不起作用?

每隔3个项目交替显示,然后每1个项目交替显示

Plotly.js栏为x轴栏添加辅助文本

MAT-TREE更多文本边框对齐问题

如何为两条动态路由创建一个页面?