0

I have two associative arrays and want to push one completely to the other.

my current code:

LT_WORK_PACKAGE.data[i].STOCK_DOCCAT = stock_data.STOCK_DOCCAT;
LT_WORK_PACKAGE.data[i].STOCK_DOCNO  = stock_data.STOCK_DOCNO;
LT_WORK_PACKAGE.data[i].STOCK_ITMNO  = stock_data.STOCK_ITMNO;

im looking for something like this:

LT_WORK_PACKAGE.data[i].push(stock_data);
1
  • I dint get your question but you have to do like this if you are pushing LT_WORK_PACKAGE.data.push(stock_data); Commented Jun 27, 2019 at 12:51

2 Answers 2

2

.push is for adding items to an array. You do have an object , and to copy multiple properties into an object,you can use Object.assign:

Object.assign( 
 /*to:*/ LT_WORK_PACKAGE.data[i],
 /*from:*/ stock_data
);
Sign up to request clarification or add additional context in comments.

Comments

0

You can use LT_WORK_PACKAGE.data[i] = stock_data.

Note that the previous content (if it exists) of LT_WORK_PACKAGE.data[i] will be replaced by a reference to stock_data. Any changes made in stock_data will be done in LT_WORK_PACKAGE.data[i] If you want a copy, you can use : LT_WORK_PACKAGE.data[i] = JSON.parse(JSON.serialize(stock_data))

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.