42
rated 0 times
[
44]
[
2]
/ answers: 1 / hits: 25915
/ 7 Years ago, fri, october 27, 2017, 12:00:00
I'm working with an object containing properties with values that are either type string or type number. Some properties are nested objects, and these nested objects also contain properties with values that could be either type string or type number. Take the following object as a simplified example:
var myObj = {
myProp1: 'bed',
myProp2: 10,
myProp3: {
myNestedProp1: 'desk',
myNestedProp2: 20
}
};
I want all of these values to be type string, so any values that are type number will need to be converted.
What is the most efficient approach to achieving this?
I've tried using for..in and also played around with Object.keys, but was unsuccessful. Any insights would be greatly appreciated.
More From » object