🐛 버그

Date 객체를 JSON.stringfy(), JSON.parse() 할 때

yeonDev 2021. 12. 27. 09:49

Date 값에 toLocaleDateString() 함수를 사용했더니 다음과 같은 오류가 발생했다.

item.due.toLocaleDateString is not a function.

 

item.due가 Date 객체로 인식되지 않아서 생긴 오류이다. 혹시 해당 값을 JSON.stringfy()한 후 다시 JSON.parse() 했다면 item.due 값이 객체가 아니라 string으로 콘솔에 찍힌다. new Date()로 감싸서 다시 객체로 만들어주자.

 

new Date(item.due).toLocaleDateString()