0

After I use JSON.parse some field gets empty string value.

I get the data using localStorage.getItem("letter_" + i); Then we have:

{"id":2,"body":"heyyy","attachfilephoto":"","private_attachfilephoto":"de0371e568a0449f29d5d4e644ff20e7|98472274636224c27e2033fdd6c4d790|3adb5e0829e56d8dc1a47134885eaf3a|","short_video_attachfilephoto":"","select_vg_id":""}

After JSON.parse(template); we have the next:

result of JSON.parse

But when I click to open arrow the private_attachfilephoto field gets empty string:

Empty field

Why private_attachfilephoto gets empty string ?

Code part:

return new Promise((resolve, reject) => {
                   var templates = [];
                   for(var i = 1; i <= 3; i++) {
                       var template = localStorage.getItem("letter_" + i);
                       console.log(template);
                       if(template) {
                           template = JSON.parse(template);
                           console.log(template);
                           templates.push(template);
                       }
                   }
                   console.log(templates);
                   resolve(templates);
                });
Mikael
  • 1,209
  • 1
  • 16
  • 47
  • 2
    This cannot be reproduced with the given sample. My guess would be that you're manipulating the object afterwards, and Chrome's console only catches up when you expand the object. – deceze May 23 '19 at 07:53
  • It's possible the object is modified between the time you see the "preview" (the collapsed view), and when you expand it. I suggest you stringify your object when printing it in the console with `JSON.stringify` – Seblor May 23 '19 at 07:53
  • Thank you guys! I have added code, maybe it helps. Because I am confused with this behavior – Mikael May 23 '19 at 07:56

0 Answers0