0

I have a JavaScript array, copyCommands, that I want to push some items into. However, I can't seem to correctly add another array of items into the parent object autoGenData.

//autoGenData is the object, copyCommands is an array

        autoGenData.copyCommands.push({
            CopyFrom: UnitFrom,
            //CopyTo: //array that needs to hold CopyOptions and Unit
        });

            //Need to add these into CopyTo 
            //CopyOptions: checkedItems,
            //Unit: localUnitTo

What's the proper syntax for adding CopyOptions and unit to the CopyTo portion of the push command?

2
  • Are CopyOptions and Unit also arrays? Commented May 25, 2017 at 20:23
  • They are elements of an array that I want to create -- copyTo. Commented May 25, 2017 at 20:31

2 Answers 2

1

I think you are looking for something like this:

autoGenData.copyCommands.push({
  CopyFrom: UnitFrom,
  CopyTo: {
    CopyOptions: checkedItems,
    Unit: localUnitTo
  }
});
Sign up to request clarification or add additional context in comments.

2 Comments

This is it! Didn't realize you could write a nested command like that.
Isn't CopyTo an array of CopyOptions and Unit?
0

You can try the following:

var x = [1, 2, 3, 4];
var y = [5, 6, 7];
x.push(...y);

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.