sandbox-stringifier-object
by shan10213223
JavaScript
let obj1 = {num: 0, string: "This is a string", func: function(){}, emptyString: "", null: null, undefined: undefined};
//console.log(JSON.stringify(obj1));
//console.log(obj1);
//console.log(Object.keys(obj1));
//var object = { last_name: "john", age: 23, city: "London" };
//object = Object.assign({ first_name: "Samuel" }, object);
//console.log(object);
let obj2 = {x: 5};
let outObj2 = {};
let strObj2 = '';
for (let key in obj2) {
let tempKey = '"' + key + '"';
let tempVal = obj2[key];
outObj2[tempKey] = tempVal;
strObj2 += tempKey + ':' + tempVal;
}
console.log(outObj2);
let mockObj2 = '{' + outObj2 + '}';
//console.log(mockObj2);
let jsonOut = JSON.stringify(obj2);
console.log(jsonOut);
let funcOut = '{' + strObj2 + '}';
console.log(funcOut);
console.log(jsonOut === funcOut);
let outObj = {};
for (let key in input) {
if (Object.prototype.hasOwnProperty.call(input, key)) {
//console.log(input[key]);
console.log(key, input[key]);
let temp_key = '"' + key + '"';
let temp_val;
if (input[key] === undefined) {
temp_val = undefined;
} else {
temp_val = stringifierBasics (input[key]);
}
console.log(temp_key, temp_val);
//outObj += temp_key +
outObj[temp_key] = temp_val;
}
}