Created
November 24, 2015 08:11
-
-
Save LincolnBurrows/b9dc20f13e87d4ee68ec to your computer and use it in GitHub Desktop.
json中添加json操作
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 json_in_json = {}; | |
var user1 = {"_id":"1","name":"LincolnBurrows","age":"26","sex":"male"}; | |
var user2 = {"_id":"2","name":"yangdong","age":"20","sex":"male"}; | |
var user3 = {"_id":"3","name":"jingjing","age":"19","sex":"female"}; | |
json_in_json[user1._id] = user1; | |
json_in_json[user2._id] = user2; | |
json_in_json[user3._id] = user3; | |
console.log(json_in_json); | |
if(json_in_json[user1._id]!=undefined) | |
console.log(json_in_json[user1._id]); | |
//or | |
if(!(user1._id in json_in_json)) | |
console.log(json_in_json[user1._id]); | |
//or | |
if(json_in_json.hasOwnProperty(user1._id)) | |
console.log(json_in_json[user1._id]); | |
//删除 | |
delete json_in_json[user1._id] | |
console.log(json_in_json); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment