How to use a nested object as a function parameter? [duplicate]

Multi tool use
Multi tool use

How to use a nested object as a function parameter? [duplicate]



This question already has an answer here:



The following example is working:


const data1 =
first: 1,
second: 2
;

const data2 =
first: 'first',
second: 'second'
;

function test(obj)
console.log(obj.first, obj.second);


test(data1); // 1 2
test(data2); // first second



What do I have to do when I have data1 and data2 as nested objects in another object?


const data =
data1:
first: 1,
second: 2
,
data2:
first: 'first',
second: 'second'




This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






test(data.data1)? Is that what you're looking for?

– Pointy
Sep 11 '18 at 14:59


test(data.data1)






:( It's so stressful when you spend several minutes writing a long good answer with examples and snippet and explanations, and suddenly the question is closed. Please, do not close question so quickly!

– Damián Pablo González
Sep 11 '18 at 15:17






Same here @DamiánPabloGonzález :|

– CodeDraken
Sep 11 '18 at 15:22




1 Answer
1



You can just pass the nested objects as parameters to the test function:


test


const data =
data1:
first: 1,
second: 2
,
data2:
first: 'first',
second: 'second'

;

function test(obj)
console.log(obj.first, obj.second);


test(data.data1); // 1 2
test(data.data2); // first second






That's it. I was a little bit confused. I thought I had to modify the function parameter to get access to nested objects, e.g. function test(obj.obj)

– j0ck
Sep 11 '18 at 15:19



function test(obj.obj)

Y7e0Kauutau
QvdMETp31Agb4tjC2zqI v,es1,f1AZNBkabGcUd Esu7pp wqSj7BS3q4y0bIiK0LJOh2l

Popular posts from this blog

Old paper Canadian currency

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế