Let's get right the issue, I need to remove all functions from a object to send via socket.io JSON! Let's say I have an object such as...
let myObject = {
test1: "abc",
test2: function() {
console.log("This is a function");
},
test3: {
test4: "another string",
test5: function() {
console.log("another function");
},
test6: 123
}
}
and I need to convert it too
let myObject = {
test1: "abc",
test3: {
test4: "another string",
test6: 123
}
}
I have tried many cod methods, all of which failed! I would post them but that would be wasting your valuable time. I'd love anyone who could fix this problem in a neat function manner. Yours Truly, Jacob Morris
P.S. Here is a piece of c**p attempt at doing this
let myObject = {
test1: "abc",
test2: function() {
console.log("This is a function");
},
test3: {
test4: "another string",
test5: function() {
console.log("another function");
},
test6: 123
}
}
let i = [];
function tsfr(ls) {
let i = {};
for (let a in ls) {
if (typeof(ls[a]) !== "function") {
let d = ls[a];
if (typeof(d) == "object") {
d = tsfr(d);
}
i[a] = d;
}
}
return i;
}
i = tsfr(myObject);
console.log(i)