Try to use this, If your data format looks like that. I think CSV is the best rather than excel. Follow the second solution without JavaScript library dependency.
Solution 1
var array1 = ["Item 1", "Item 3"];
var array2 = ["Item 2", "Item 4"];
let noDuplicate = array1.filter(i => array2.findIndex(a => i == a) == -1);
let result = [...noDuplicate, ...array2];
console.log(result);
exportToExcel = function() {
var myJsonString = JSON.stringify(result);
var blob = new Blob([myJsonString], {
type: "application/vnd.ms-excel;charset=utf-8"
});
saveAs(blob, "Report.xls");
};
Solution 2, Without FileSaver.js
var Results = [array1, array2];
exportToCsv = function() {
var CsvString = "";
Results.forEach(function(RowItem, RowIndex) {
RowItem.forEach(function(ColItem, ColIndex) {
CsvString += ColItem + ",";
});
CsvString += "\r\n";
});
CsvString = "data:application/csv," + encodeURIComponent(CsvString);
var x = document.createElement("A");
x.setAttribute("href", CsvString);
x.setAttribute("download", "somedata.csv");
document.body.appendChild(x);
x.click();
};
You can find the saveAs method to the following JavaScript file, add this JavaScript file to your application. https://github.com/eligrey/FileSaver.js/blob/master/src/FileSaver.js
DEMO