Skip to content

Instantly share code, notes, and snippets.

@Sysetup
Created October 4, 2016 22:19
Show Gist options
  • Save Sysetup/791d1a55726ac5d744687ac07a3f9fe9 to your computer and use it in GitHub Desktop.
Save Sysetup/791d1a55726ac5d744687ac07a3f9fe9 to your computer and use it in GitHub Desktop.
Basic access to objects and JSON data.
var config1 = {
local: {
mode: 'local',
port: 3000,
mongo: {
host: '127.0.0.1',
port: 27017
},
connect : [3,2,1,0],
'sock' : [3,2,1,0]
},
staging: {
mode: 'staging',
port: 4000,
mongo: {
host: '127.0.0.1',
port: 27017
}
}
}
//Accessing:
console.log('Config 1: '+config1.local.connect[1]);
console.log('Config 1: '+config1.local.sock[0]);
console.log('Config 1: '+config1.staging.mongo.host);
/////////
/////////
var config2 = [{
local: {
mode: 'local',
port: 3000,
mongo: {
host: '127.0.0.1',
port: 27017
},
connect : [3,2,1,0],
'sock' : [3,2,1,0]
},
staging: {
mode: 'staging',
port: 4000,
mongo: {
host: '127.0.0.1',
port: 27017
}
}
}]
//Accessing:
console.log('Config 2: '+config2[0].local.connect[1]);
console.log('Config 2: '+config2[0].local.sock[0]);
console.log('Config 2: '+config2[0].staging.mongo.port);
/////////
/////////
var config3 = '{\
"local": {\
"mode": "local",\
"port": "3000",\
"mongo": {\
"host": "127.0.0.1",\
"port": "27017"\
},\
"connect" : [3,2,1,0],\
"sock" : [3,2,1,0]\
}\
}';
//Accessing:
var config3 = JSON.parse(config3);
console.log('Config 3: '+config3.local.mongo.host);
console.log('Config 3: '+config3.local.sock[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment