var test= [
{
applytime: 1637993230077,
},
{
applytime: 1637993230077,
},
{
applytime: 1637993230078,
},
{
applytime: 1637993230078,
},
]
function checkSameData(tableData2){
let cache = {}; //存储的是键是applytime 的值,值是applytime 在indeces中数组的下标
let indices = []; //数组中每一个值是一个数组,数组中的每一个元素是原数组中相同applytime的下标
tableData2.map((item,index)=>{
let applytime = item.applytime;
let _index = cache[applytime];
if(_index!==undefined){
indices[_index].push(tableData2[index])
}else{
cache[applytime] = indices.length
indices.push([ tableData2[index]])
}
})
console.log(indices)
}
this.checkSameData(test)
js找出数组中相同的元素放在一起
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 1. 找出两数组中不相同的元素的集合 平时需求中经常遇到,找出两数组中不相同的部分。有时候会要找出被删除的元素。 ...
- <!DOCTYPE html> Document //做比较的两个数组var array1 = [...
- 题目三: 2.23如果一个数组A[1...n]中超过半数的元素都相同时,该数组被称为含有一个主元素。给定一个数组,...