Your code has a number of issues:
function()
{
Is a syntax error, function declarations require a function name.
datearry = ("i"+"p2"+"p3");
datearray is initialised as an array, but here a string literal is assigned (literally "ip2p3"). You probably meant:
datearray.push(String(i) + p3 + p3);
which will add a string like "26042020" the first time, however as the algorithm progresses and the strings are turned into numbers, you'll start to get values like "152020" for 1 March 2020. So you need some padding, and probably a delimiter, to get "01-05-2020" and match the input format.
Lastly, the code doesn't seem to correctly accommodate transitions over month and year boundaries. Fixing that really isn't useful as it's much more complex than it needs to be or I'm prepared to bother with given there are much simpler alternatives. :-)
If you're looking for an array of timestamps between two dates, one strategy is to convert the timestamps to dates, then loop over the required range storing the required output timestamps in an array.
Existing questions deal with how to parse a date string and how to format a date. You can put those together to create a function something like the following:
// startDate, endDate in format dd-mm-yyyy
// Return array of dates inclusive of start and end in same format
function getDateRange(startDate, endDate) {
// Parse dd-mm-yyyy
let qParse = s => {
let [d, m, y] = s.split(/\D/);
return new Date(y, m-1, d);
};
// Format date as dd-mm-yyyy
let qFormat = d => {
let z = n => (n<10? '0' : '') + n;
return z(d.getDate())+'-'+z(d.getMonth()+1)+'-'+d.getFullYear();
}
// Setup for loop
let start = qParse(startDate);
let end = qParse(endDate);
let result = [];
// Loop from start to end, incrementing
// the start date and writing to result array
do {
result.push(qFormat(start));
start.setDate(start.getDate() + 1);
} while (start <= end)
return result;
}
console.log(getDateRange('26-02-2020','03-03-2020'));
// Different delimiters in input
console.log(getDateRange('28.12.2020','03/01/2021'));
You should also validate the input. The parse and format functions are closed in the function as they're only designed to work with the specific format of the OP (i.e. they aren't general parsing or formatting functions).