https://www.dendron.so/ logo
This is an odd place to ask but would someone mind...
# chat
p
This is an odd place to ask but would someone mind helping me out with some JavaScript? I'm having trouble getting the proper output of JSON object
s
Sure, what is it?
p
you roooock
s
😄
p
actually lemme push current real quick
I'm trying to iterate over this object, it's a file tree output. I can't seem to go as deep as the first child it outputs like this
Copy code
[
  {
    path: 'local/gallery/MSF_renders',
    name: 'MSF_renders',
    children: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object]
    ],
    type: 'directory'
  },
  {
    path: 'local/gallery/MX',
    name: 'MX',
    children: [ [Object], [Object], [Object] ],
    type: 'directory'
  },
  {
    path: 'local/gallery/mpn45_renders',
    name: 'mpn45_renders',
    children: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object]
    ],
    type: 'directory'
  },
  {
    path: 'local/gallery/mx_suppressed',
    name: 'mx_suppressed',
    children: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object]
    ],
    type: 'directory'
  }
]
code I was attempting but it's probably gibberish now since I was at the point of brain mush
s
I'm not sure what's the issue, is it that you parse the json, but then you can't iterate on the parsed object?
p
When I try to access the other children, they're only outputting as [Object] instead of displaying the actual properties
i could possibly be explaining this horribly but for the most part, I can output that entire object, but I don't know how to get deeper into it I guess
s
Can you access the actual properties? Like if you did:
Copy code
for (let i = 0; i < gObj["children"]; i++){
    console.log(gObj["children"].type);
}
I'm guessing this is just a printing issue, I don't see why it wouldn't work otherwise
p
I can't
earlier I was just trying to grab the filepaths, and it was coming out as just the first local/gallery filepath rather than including the children as well
well i wouldn't say 'can't that's not showing up in output at all
s
Hmm, give me a sec and I'll try running the code to see what happens
p
thanks homie sorry about this hahaha
s
No problem! Here's what I'm seeing:
Copy code
> y.children
[
  {
    path: 'local/gallery/MSF_renders',
    name: 'MSF_renders',
    children: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object]
    ],
    type: 'directory'
  },
    // ...
]
> y.children[0]
{
  path: 'local/gallery/MSF_renders',
  name: 'MSF_renders',
  children: [
    {
      path: 'local/gallery/MSF_renders/MSF_hires',
      name: 'MSF_hires',
      children: [Array],
      type: 'directory'
    },
    {
      path: 'local/gallery/MSF_renders/hubi20046.jpg',
      name: 'hubi20046.jpg',
      type: 'file',
      extension: '.jpg'
    },
    // ...
  ],
  type: 'directory'
}
> y.children[1]
{
  path: 'local/gallery/MX',
  name: 'MX',
  children: [
    {
      path: 'local/gallery/MX/mx_skinned01.jpg',
      name: 'mx_skinned01.jpg',
      type: 'file',
      extension: '.jpg'
    },
    // ...
  ],
  type: 'directory'
}
So like I thought, it is a problem of printing.
console.log
chooses what it wants to show, and what it wants to abbreviate with
[Object]
.
p
Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
...
.............
this is almost like not noticing that you'd had used a [ instead of a } for weeks when you first started
s
😄
p
bro thanks so much for taking the time out of your day to help
s
Yeah no problem, hope you have a good rest of your day
p
you as well
RAGE
i mean have a good one