Created
October 4, 2016 22:19
-
-
Save Sysetup/791d1a55726ac5d744687ac07a3f9fe9 to your computer and use it in GitHub Desktop.
Basic access to objects and JSON data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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