Hello. There is such code:
class User { constructor(id, username, date){ this.id = id; this.username = username; this.date= date; } } let myUsers = [ new User(1, 'Mark', new Date('03.01.2016')), new User(2, 'Jacob', new Date('02.02.2016')), new User(3, 'Petr', new Date('01.02.2016')) ]; I turn this array into JSON and store it in local storage.
localStorage.setItem('myUsers', JSON.stringify(myUsers)); Then get out and perform the parsing
let users = localStorage.getItem('myUsers'); users = JSON.parse(users); When I try to display a formatted date
users.forEach(function(user){ console.log(user.date.getDate()); }); reports an error
Uncaught TypeError: user.date.getDate is not a function As I understand it, this happens because after parsing I get a string, not an object with a date. Actually this is the question. How to get the opportunity to work with the properties of the object in this case?
JSON.parse()get instances of objects of classUser, but it is not. - teran