Linked Questions

936 votes
32 answers
221k views

Is there any way to get something like the following to work in JavaScript? var foo = { a: 5, b: 6, c: this.a + this.b // Doesn't work }; In the current form, this code obviously throws ...
kpozin's user avatar
  • 27.2k
1 vote
2 answers
2k views

My question is somewhat simple, but IDK if I haven't made the search with the right keywords, but my problem is: When defining an object in JS/TS, how can I use one value from the obj into another key,...
Régis Faria's user avatar
0 votes
1 answer
1k views

var fighters = ['johnjones', 'rondarousey', 'connormcgregor', 'chuckliddel', 'demetriusjohnson']; var warriors = { wrestlers: ['randysavage', 'hulkhogan', 'ultimatewarrior', 'jakethesnake', '...
J. Bones's user avatar
  • 489
0 votes
3 answers
294 views

I am getting: "Uncaught TypeError: Cannot read property '0' of undefined at newTipCalc.js:4" Can anybody tell what is wrong: var johnTipCal = { name: 'John Smith', bills: [124,48,...
Anurag Sharma's user avatar
1 vote
1 answer
206 views

I'm trying to call this inside a nested object in an array in node.js, but it's returning undefined. var foo = { dog: 'max', cat: { names: [ { grey: this.dog } ] ...
Nick Blexrud's user avatar
  • 9,601
-2 votes
1 answer
275 views

I am trying to initialize an object and and assign a property of its own to one of the properties. But my syntax is incorrect.i am referring to the following line: PCMACUrl = genericURL + "/test" i ...
user3649212's user avatar
-1 votes
1 answer
68 views

I'm doing to subtract inside the json is this possible? @employees = [ { "name": "Fullname1" "vl": "Vacation Leave", "vl_days": "15.0", "sl": "Sick Leave", "sl_days": "10.0", "bday": "...
ImpostorIsAsking's user avatar
0 votes
1 answer
46 views

let obj = { a:2, b: this.a, }; console.log(obj.a); //outputs 2 console.log(obj.b); //outputs undefined Why can't I access one property of an object from another property within the same ...
Gsbansal10's user avatar
0 votes
0 answers
34 views

I am having the following object: obj = config { commonId: "id-goes-here", option1 : { value : "", link : "some-link/" + commonId should go here }, option2 : { ...
Laurens Mäkel's user avatar
0 votes
1 answer
33 views

let mario = { x: 20, w: 20, h: 40, y: canvas.height-mario.h, speedX: 0, speedY: 10, dx: 4, dy: -7, color: "black", canJump: true, onGround: true,...
HelptimeCode's user avatar
235 votes
8 answers
160k views

Lets say I have the following JavaScript: var obj = { key1 : "it ", key2 : key1 + " works!" }; alert(obj.key2); This errors with "key1 is not defined". I have tried ...
Erin Drummond's user avatar
11 votes
3 answers
16k views

I thought I understood the relationship between this and arrow functions but the following snippet is making me question my understanding. let person = { name: 'Jim', sayName: () => { ...
Tekeste Kidanu's user avatar
8 votes
4 answers
752 views

I want to set two properties equal to each other in one object. Here's an example: var obj = { // I want to do something like this a: function() { ... }, b: alert, c: a }; Obviously that ...
qwertymk's user avatar
  • 35.6k
2 votes
3 answers
2k views

How to reference an object inside itself? As you can see below I'm creating an unnamed object inside the console.log console.log({ x: 2, y: this.x * 2, }); I'm not assigning it to ...
mx_code's user avatar
  • 2,537
5 votes
3 answers
241 views

Assuming I have the following object: let obj={ childone: (value) => { return value+1; }, childtwo: (value) => { return value+3; }, childsingle: (value) =>...
Vixed's user avatar
  • 3,499

15 30 50 per page