我读过一些帖子,其中重复项从数组中删除。例如,具有“one”,“one”,“two”,“three”的数组将使用我在某些帖子中找到的代码返回“one”,“two”,“three”。我需要删除两个值,所以“一个”,“一个”,“两个”,“三个”将返回“两个”,“三个”。我正在解析文件并根据正则表达式搜索项目。这是我的代码。虽然有时候我正在解析的文件中有重复的数据。我需要删除这些数据。删除对象数组中的重复项
function parseText(text)
{
var records = text.match(fileRegex);
var fileArray = [];
if (records != null) {
records.forEach(function (element, index, array) {
var matches = elementRegex.exec(element);
if (matches != null) {
var year = matches[parseSettings.ParseYearPosition];
if (year == 2)
{
year = "20" + year;
}
var journalDate = new Date(year,
matches[parseSettings.ParseMonthPosition] - 1,
matches[parseSettings.ParseDayPosition],
matches[parseSettings.ParseHourPosition],
matches[parseSettings.ParseSecondPosition], 0, 0);
var file = {
Id: null,
ImportDate: moment(importDate).format(),
JournalDate: moment(journalDate).format(),
TraceNumber: parseInt(matches[parseSettings.ParseTraceNumberPosition]),
Amount: parseFloat(matches[parseSettings.ParseAmountPosition]),
Deleted: false,
Dirty: true
};
fileArray.push(file);
}
});
deferred.resolve(fileArray);
}
的(HTTP [从对象在JavaScript数组删除重复]可能重复。 com/questions/2218999/remove-duplicates-from-an-a-array-of-objects-in-javascript) –