function parse(obj){
const result={};
for(let key of Object.keys(obj)){
let keys=key.split(".");
let temp=result;
while(keys.length>1){
let tempKey=keys.shift();
if(!temp[tempKey]) temp[tempKey]={};
temp=temp[tempKey]
console.log(temp,result)
}
temp[keys.pop()]=obj[key]
}
return result;
}
var d={'a.b.c':'1',"a.d":2,'fff':'ggg'};
var res=parse(d);
console.log(res)
var obj= {"a":{"b":{"c":"1"},"d":2},"fff":"ggg"}
function getKeys(obj) {
//es6新语法 Object.prototype.toString()方法精准判断参数值属于哪种类型
if(Object.prototype.toString.call(obj) === "[object Object]") {
var arr = [];
var arrValue = [];
var arrKeyValue = [];
(function getKeysFn(o, char) {
for(var key in o) {
//判断对象的属性是否需要拼接".",如果是第一层对象属性不拼接,否则拼接"."
var newChar = char == "" ? key : char + "." + key;
if(Object.prototype.toString.call(o[key]) === "[object Object]") {
//如果属性对应的属性值仍为可分解的对象,使用递归函数继续分解,直到最里层
getKeysFn(o[key],newChar);
} else {
arrValue.push(o[key]);
arr.push(newChar);
arrKeyValue.push(newChar + "=" + o[key]);
}
}
})(obj,"");
console.log(arr);
console.log(arrValue);
console.log(arrKeyValue);
} else {
console.log("传入的不是一个真正的对象哦!");
}
}
getKeys(obj);
console