标签:pre 字符串 字符 eval try string eof trie --
1. String --->Object // 待转化字符串 var str = ‘{"name":"lxh","add":"China"}‘; // 字符串转化为Object var obj = eval(‘(‘+str+‘)‘); // 判断obj类型 typeof(obj) // 获取转换后的对象 var entry = Object.entries(obj); // 获取转换后对象的key var key = Object.keys(obj); 2. Object --->String // 将上面的obj转换为string var str = JSON.stringify(obj); 3. Object 深拷贝 <1> 使用JSON var obj = {name: "lxh", add: "China", age: 40}; var cloneObj = JSON.stringify(obj); cloneObj = = JSON.parse(cloneObj ); obj.age = 40; <2> lodash http://lodash.think2011.net/cloneDeepWith var obj = {name: "lxh", add: "China", age: 40}; var cloneObj = _.cloneDeepWith(obj);
标签:pre 字符串 字符 eval try string eof trie --
原文地址:https://www.cnblogs.com/lvlin241/p/12716013.html