How to add Object to the array of object in javascript -


i'd add object array of object.

my array in jsfiddle: https://jsfiddle.net/5w4zhw92/

the expected

var sensors = [ { id: 'led', name: 'led', type: { port: '', path: '' } }, { id: 'temp', name: 'temp', type: { path: '' } }, ]; 

it's working need declare variable before using it.declare sensortype first use it.

var sensortype = {     sender: {         port: '',         path: ''     },     receiver: {         path: ''     }     }; var sensors = [     { id: 'led', name: 'led', type: sensortype.sender },     { id: 'temp', name: 'temp', type: sensortype.receiver }     ];      console.log(sensortype.sender);     console.log(sensors); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -