I have two arrays which starts off as this:
let days = [null, null, null, null, null, null, null];
const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
Depending on what data I'm given, I want to map a new array with the corresponding weekday, but still keep it the same size array.
let numDays = ["0","2","4"]
let days = days.map(?)
days
> ['Sunday', null, 'Tuesday', null, 'Thursday', null, null]
I have attempted a conversion function which can convert numDays to its correspondingweekdays
const convert = function (c) {
return weekdays[c];
}
numDays.map(convert)
> ['Sunday', 'Tuesday', 'Thursday']
But not sure how to retain the array size for the result I need.
Cheers!
mapreturns an array with the same size of the array you are executing it on. you can not simply usemapfor that.mapondayswhich will give me the correct array size (7 elements). My question is figuring out how to usenumDaysas a reference index to replace theweekdaysindays.