JS Stringify & parse

Heewon👩🏻‍💻·2024년 4월 26일
const playList = {title: Ditto}
JSON.stringify(playList)
{"title":"ditto"}

설명: JSON.stringify()는 object건 array또는 어떠한 js코드를 String으로 변환시켜준다.

중요한 이유는 localStorage에 배열 형식으로 저장해야 페이지가 reload되어도 값을 불러올 수 있기 때문!

const playList = {title: Ditto}
JSON.stringify(playList);
{"title":"ditto"}

const boringString = JSON.stringify(playList);
JSON.parse(boringString)

string type으로 변환된 playList를 boringString변수에 입력시킨뒤 JSON.parse()에 넣어주면 다시 String에서 Object로 변환된걸 알 수 있다.

profile
Interested in coding, meat lover, in love with dogs , enjoying everything happens in my life.

0개의 댓글