我有一个解析的CSV文件,格式如下:
const data = [
["ID", "Full name", "pHone", "Email", "Age", "Experience", "Yearly Income", "Has children", "License states", "Expiration date", "License number", "Duplicated With"],
[1, "Alex Cho", "+18900991919", "cho.cho@gmail.com", "12", "21", "200", "FALSE", "AL | New York | District of Columbia | Montana", "12-12-2030", "1xr567", null],
[2, "Alex Cho", "1900991919", "12351235@yandex.ru", "0", "12", "true", "TRUE", "Alabama | American Samoa", "12/31/1998", "1xr567", null].
[3, "Alex Cho", "8982394689", "alex.swarts@ukr.net", "-1", "8", "1200.11", "FALSE", "Northern Mariana Islands", "date", "kas317", null],
[4, "Alex Cho", "18900991919", "cho.cho", "-99", "100", "1200.100", "YES", "Palau", "02-11-2021", "1nasd567213", null],
[5, "Alex Cho", "+18900991919", "testEmail@gmail.com", "11", "11", "12..00.11", "NO", "Puerto Rico", "04-11-2021", "1xr567!(%^!@)", null],
[6, "Alex Cho", "+18900991919", "@!%*!&@!@@gmail.com", "100", "10", "999999.11", " ", "West Virginia | North Carolina | North Dakota", "12/31/2022", "1xr*@#", null],
[7, "Alex Cho", "+10950943225", "(*!&@^$%12481Asd@gMAIL.com)", "44", "10", "12.00.11", "TRUE", "Virgin Islands", " 2022-12-03", "1xr___", null],
[8, "Alex Cho", "+10950943225", "(*!&@^$%12481Asd@gMAIL.com)", "44", "10", "12.00.11", "TRUE", "Virgin Islands", " 2022-12-03", "ABC123", null],
]现在我需要检查它的电子邮件和电话的副本,如果电话或电子邮件将是相同的任何项目,我需要注意到它,并在我创建的最后一栏“复制与”标记。如果您可以在图片上看到,有一个额外的列,必须有一个重复的ID。
但我也不知道该怎么实现。

发布于 2021-03-11 20:48:04
我希望我能正确理解你的要求。你似乎需要这样的东西:
const data = [
["ID", "Full name", "pHone", "Email", "Age", "Experience", "Yearly Income", "Has children", "License states", "Expiration date", "License number", "Duplicated With"],
["1", "Alex Cho", "+18900991919", "cho.cho@gmail.com", "12", "21", "200", "FALSE", "AL | New York | District of Columbia | Montana", "12-12-2030", "1xr567"],
["2", "Alex Cho", "1900991919", "12351235@yandex.ru", "0", "12", "true", "TRUE", "Alabama | American Samoa", "12/31/1998", "1xr567"],
["3", "Alex Cho", "8982394689", "alex.swarts@ukr.net", "-1", "8", "1200.11", "FALSE", "Northern Mariana Islands", "date", "kas317"],
["4", "Alex Cho", "18933991919", "cho.cho", "-99", "100", "1200.100", "YES", "Palau", "02-11-2021", "1nasd567213"],
["5", "Alex Cho", "+18900991222", "testEmail@gmail.com", "11", "11", "12..00.11", "NO", "Puerto Rico", "04-11-2021", "1xr567!(%^!@)"],
["6", "Alex Cho", "+18933991919", "@!%*!&@!@@gmail.com", "100", "10", "999999.11", " ", "West Virginia | North Carolina | North Dakota", "12/31/2022", "1xr*@#"],
]
const new_data = data.map((item, index) => {
const clean_phone = item[2].replace(/^(\+1|^1)/,""); //Clean up the phone number
const dup_ids = [];
data.forEach((element, ind) => {
if((index !== ind) && (element[2].includes(clean_phone) || item[3] === element[2]))
dup_ids.push(element[0])
})
index && item.push(dup_ids);
return item;
});
console.log(new_data)
这将为您提供相同的数组,但在同一个数组中添加一个由电话或电子邮件找到的所有重复“in”的数组。
发布于 2021-03-11 20:37:38
你至少有两个选择:
。
https://stackoverflow.com/questions/66589721
复制相似问题