How to add an object into an object

Posted by FlyingCat on Stack Overflow See other posts from Stack Overflow or by FlyingCat
Published on 2014-08-18T22:20:39Z Indexed on 2014/08/19 4:21 UTC
Read the original article Hit count: 155

Filed under:

I am trying to add an object into another object.

My previous post helped me on the array issue but I also need to add object into an object too.

I have something like

var temp = {};

for(var i=0; i<test.length; i++){
    console.log(test[i])
    console.log(product[i])
    temp.test[i] =product[i];
}

Both of console.log show values. However, I am getting

"Uncaught TypeError: Cannot set property '0' of undefined" for the temp.test[i] =product[i]

Can someone help me out on this? Thanks a lot

© Stack Overflow or respective owner

Related posts about JavaScript