Help getting Javascript to work

So I got my code to work but now it says that my name is undefined and cannot be assigned

TypeError: Cannot set property '♡Yuzi♡' of undefined

Here is my javascript:

    let player = message.author.username;
    let data = new Object();
    if(playerArea [player] === undefined) {
      createID [data][player] = {usedactivate: 0}         //This is that part I cant assign
      fs.writeFile('./PlayerArea.json', JSON.stringify (createID, null, 4), err => {
        if (err) throw err;
      })
    }

Im trying to create data as a container and player as a container but it wants me to assign a value to it which I dont want to do. Anyone know anyway around this?

Assuming that Yuzi is a player, then I think that is saying that createId[data] is evaluating to undefined. You can only set props on an object, not undefined.

…because data is not a string or symbol, but this:

Did you mean this?

if(!playerArea[player]) {
  data[player] = { usedactivate: 0 };
  fs.writeFile('./PlayerArea.json', JSON.stringify (data, null, 4), (err) => {
    if (err) throw err;
  });
}

I tried your fix but its still saying that player is undefined

TypeError: Cannot read property '♡Yuzi♡' of undefined
    let player = message.author.username;
    let data = new Object();
    if(player === undefined) {
      player = {};
    }
    if(playerArea [data][player] === undefined) {
      data[player] = {usedactivate: 0}
      fs.writeFile('./PlayerArea.json', JSON.stringify (data, null, 4), err => {
        if (err) throw err;
      })
    }

I added

if(player === undefined) { player = {}; }

Sorry, I didn’t notice that data was an object. That is really weird. It is possible in JS I think, but keep in mind that it will be using afaik the reference as the key and not the value. That may have unintended side effects and may be confusing to work on later. (When writing code, always assume that someone else will be reading it.) It would be much better to use some unique value in that obj as the key.

But it still leaves you with the problem that createID[data] is undefined so you can’t start assigning properties to it. You could try something like:

createID[data] = { [player]: { usedactivate: 0 } }; // edited for correctness

but I’m still not convinced that this is all heading in the direction it should be.

createID [data][player]
is incorrect syntax…

and also data is asigned to be this

let data = {};

I will try without the data container again but I tried and it worked before except when I have two players it was overwriting each players variables…

You do the same mistake, now in the condition. In JS object keys may only be strings or symbol:

let player = message.author.username;
let data = {}; // That would be shorter
if(!playerArea[player]) {
  data[player] = { usedactivate: 0 };
  fs.writeFile('./PlayerArea.json', JSON.stringify (data, null, 4), err => {
    if (err) throw err;
  });
}

createID [data][player]
is incorrect syntax…

In what way?

And sorry, my suggestion should have been:

createID[data] = { [player]: { usedactivate: 0 } };

and also data is asigned to be this
let data = {};

I don’t see how that changes what I said.