How to print array of objects with dates in JavaScript

1 Answer

0 votes
const oarr = [
  { day: 772, date: new Date('2022-02-18') },
  { day: 881, date: new Date('2022-01-19') },
  { day: 152, date: new Date('2023-01-30') },
  { day: 208, date: new Date('2022-02-17') },
];

for (let i = 0; i < oarr.length; i++)
	console.log(oarr[i].day  + " " + oarr[i].date.toDateString());

 
  
  
  
/*
run:
  
"772 Fri Feb 18 2022"
"881 Wed Jan 19 2022"
"152 Mon Jan 30 2023"
"208 Thu Feb 17 2022"
  
*/

 



answered Feb 22, 2022 by avibootz

Related questions

...