3

I am writing code for a simple electron based application, while working with a list of directory array its started acting weird!

Take a look at this picture:

enter image description here

At first when i console.log( dirs ) it displays all of its array elements in the console, but while using the length it show it has 0 elements! Which is not true.

Again in the loop its not traversing!

Also I am not using push method to insert new objects and arr.slice() also returns 0 array elements!

Am i missing something here?

rakibtg
  • 5,521
  • 11
  • 50
  • 73
  • Try `console.log(dirs.slice())` – Oriol Nov 25 '16 at 18:49
  • 1
    Weird. For of was supposed to iterate a property sequence in this array –  Nov 25 '16 at 18:53
  • @Oriol Hi, adding `dirs.slice()` would also return `Array[0]` Here is the screenshot https://i.stack.imgur.com/TYs0n.png – rakibtg Nov 25 '16 at 18:53
  • Its not a dup. i am not inserting any new items using push like that... – rakibtg Nov 25 '16 at 18:57
  • Well, there is something that fills your array between your `console.log` and it being displayed in the console. Blame Chrome's devtools for being misleading. I suggest using better devtools. – Oriol Nov 25 '16 at 18:59
  • This is the only dev tool available in electron, btw what you think about the loop? I did all kinds of loops to see if the child elements are there or not,, it does nothing .. i checked your marked dup. Q. its making no sense – rakibtg Nov 25 '16 at 19:02
  • That's because there are no elements. The array is empty, as shown by `dirs.slice()`. It's just that the array is populated *later*. – Oriol Nov 25 '16 at 19:03
  • `items` variable is already populated with valid informations.. – rakibtg Nov 25 '16 at 19:06
  • Can you try with `dirs=[1,2,3]` instead of `dirs=items['directories']`? – sabithpocker Nov 25 '16 at 19:06
  • @sabithpocker No, that shows undefined! – rakibtg Nov 25 '16 at 19:08
  • I think dat's a troll... It looks like yourself planned it, you put elaborated images at the question with this intention, isn't it? Or this array may have secret getters/setters, or even proxies. –  Nov 25 '16 at 19:23
  • Can you try `delete console.log` / `delete window.console` before using it. To restore `console.log` in browser if it was modified by your framework. – sabithpocker Nov 25 '16 at 19:39
  • @FREEZE No! Why you even think that! Oriol was right, data was targeted before the array populates! – rakibtg Nov 25 '16 at 20:01

0 Answers0