I want the result to be like
What you've shown after that is invalid (well, okay, you could create something like that, but it's generally a bad idea*). You can create this, though:
[
{
pageContext: {
pageType: "Homepage",
label: "pageContext"
}
}
]
Note that the array contains an object, which contains pageContext.
If that's the result you want, and if _meta is really as shown, just push _meta:
myArray.push(model._meta);
Example:
const myArray = [];
const model = {
_meta: {
pageContext: {
pageType: "Homepage",
label: "pageContext"
}
}
};
myArray.push(model._meta);
console.log(myArray);
If _meta has other things in it that you don't want to push, create a new object:
myArray.push({pageContext: model._meta.pageContext});
Example:
const myArray = [];
const model = {
_meta: {
pageContext: {
pageType: "Homepage",
label: "pageContext"
},
somethingElse: {
weDontWant: "this"
}
}
};
myArray.push({pageContext: model._meta.pageContext});
console.log(myArray);
* If you really want to have an array with a pageContext property on it, you can do that, because arrays are objects:
myArray.pageContext = model._meta.pageContext;
But most of the time, if you think you want to do that, you don't want an array at all, you just want a non-array object.
myArray.pageContext = model._meta.pageContext