开发者

array.push(SomeObject) does not copy an array contained in SomeObject

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] } ]开发者_JS百科 }
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)


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜