0

I have an object like result: object which has the below parameters in it.

calcTimeHY2: "50",
calcTimeHY3: "70",
color: "GREEN",
width: "3",
channels: Array(1)

I am writing a general method to create similar result object.

I have called getClonedResult(result)

getClonedResult(result){
    let temp: any;
    var propertyNames = Object.getOwnPropertyNames(result);
    for (var name in propertyNames) {
         temp = propertyNames[name];
         if (!temp instanceof Array) {
             //Then I want to create similar object as above
            //How to do it.

         }
    }
}

I have both arrays and single values in the same object, how to clone to a new object.

code1
  • 8,351
  • 8
  • 27
  • 31
  • How to create objects is generally covered by JavaScript tutorials such as http://eloquentjavascript.net/04_data.html#h_cqg63Sxe3o or https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects. Please be more specific about your problem. – Felix Kling Mar 27 '17 at 20:38
  • My Object has both arrays and single parameters and the new object formed should have the same list as the original object passed. All the examples shown are returning individual objects, how to get all of them combined into one object. – code1 Mar 27 '17 at 20:59
  • Create the object and assign properties to it: `var obj = {}; for (...) { obj[name] = value; }`. – Felix Kling Mar 27 '17 at 21:05

0 Answers0