;
//데이터 추가
window.localStorage.setItem('데이터명', data);
//데이터 조회
window.localStorage.getItem('데이터명');
//데이터 삭제
window.localStorage.removeItem('데이터명');
예제
북마크 구현
const localStore=localStorage.getItem("BookList");
const localData:string[]=localStore&&JSON.parse(localStore);
if(markState===false && !localData.includes(book.id)){
localData.push(book.id);
localStorage.setItem("BookList", JSON.stringify(localData));
} else if(markState===true){
const filterData=localData.filter((iter)=> iter!==book.id);
localStorage.setItem("BookList", JSON.stringify(filterData));
}
주의점 .
1.string과 String 은 다르다. String 은 객체임,string은 문자열