I'm trying to populate an array 'arr' inside the object 'obj' with a property I defined inside this 'obj', in this case, the property 'x';
Basically the array would have x values, but instead, when accessing 'arr', all the entries are undefined.
What I did:
var obj = {
x: 1,
arr: [this.x, this.x, this.x],
};
console.log(obj.arr)
How should I refer to x inside the array? I tried enclosing arr with brackets, but that would only give me a syntax error. I tried searching how would this work but have found nothing useful...
Furthermore, I would like that arr to be of two dimensions, such that:
var obj = {
x: 1,
arr: [
[this.x, this.x, this.x],
[this.x, this.x, this.x],
[this.x, this.x, this.x]
],
};
console.log(obj.arr);
How would it work then?