1

The following code:

var ResultSet= { 'ResultSetName': "Resultset1",
    Values: [ { Val1: 1, Val2: 2, Val3: 'SomeName' } ] }

var AllResults= { 'MyListName': 'SomeList', 'MyResults': { Results: [] } }


AllResults.MyResults.Results.push(ResultSet);

console.log(AllResults.MyResults);
console.log(AllResults.MyResults.Values);

Produces the output:

{ Results: [ { ResultSetName: 'Resultset1', Values: [Object] } ] }
undefined

However I would expect it to produce something like:

{ Results: [ { ResultSetName: 'Resultset1', Values: [Object] } ] }
[ { Val1: 1, Val2: 2, Val3: 'SomeName' } ]

What Am I missing? Why is the array contained in the object not copied? What would be the correct way to achieve the desired result?

(I'm using node.js 1.8.2, but I het the same behavior in a browser)

1 Answer 1

1

AllResults is an object.
AllResults.MyResults is an object
AllResults.MyResults.Results is an array

AllResults.MyResults.Results[0] is your ResultSet object.

console.log(AllResults.MyResults.Results[0].Values); //This is where your Values object ended up.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.