Pushing To Array adds an ID to the object?


Confusing one here, really not sure whats happening.

As you can see below, i am only creating a from entry and a to entry in the object.

var edgesToLoad = [];
  for (var j = 0; j < dataArr.length; j++) {
    edge = {
      from: dataArr[j][1],
      to: dataArr[j][0]

However on the output there is an ID with some random hash looking value?


Does anyone know why this is happening? or is there a way i can prevent this from happening?

EDIT Doesnt effect my how it works, still curious about why this happens?



1 Like

AFAIK, that extra property id shouldn’t exist! :dizzy_face:
Unless that was added to Object’s prototype somehow: :space_invader:

By any chance, are you using some library that perhaps modifies the Object’s prototype? :books:
You should host your sketch online so we can check it out ourselves. :heavy_check_mark:

1 Like


I’m using vis.js as the library as well as p5.js
I’ve only just started working with other libraries as I’ve only just come to terms with how they can be implemented.

I don’t believe this library effects the prototype object for arrays? However I’ve not dug deep into it

  • Your variable edge{} is an Object, not an Array.
  • However, adding properties to the Object’s prototype{} would also affect Array, b/c Array is a subclass of Object.
  • Actually, almost anything in JS would be affected by changes to the Object’s prototype{}.
  • In order to check whether a library is modifying the Object’s prototype{}, you can create an empty Object and print() it, like this: print({}); or console.log({});
  • If you spot anything other than __proto__: Object, something is messing w/ the Object’s prototype{}.
  • Try that out w/ a loaded & initialized “vis.js” and w/o it.