I have an array and an object and I would like to combine them by nesting the array within the object using JavaScript. I do not want to use lodash, jQuery, or any other library because my project is fairly small and I cannot add that overhead.
This is my current object and array:
var myObject = {
"key1": "value 1",
"key2": "value 2"
}
var myArray = [
{ "id": 1, "name": "name 1"},
{ "id": 2, "name": "name 2"}
]
And this is how I would like it to be structured:
var myObject = {
"key1": "value 1",
"key2": "value 2",
"myArray": [
{ "id": 1, "name": "name 1"},
{ "id": 2, "name": "name 2"}
]
}
I've tried using the JavaScript push() method, but that didn't work for me. Any guidance would be greatly appreciated. Thanks!