My goal is to create a fresh array by including an element in an existing array using the "push()" method.
Here is the original array:
let arr = [{label: 1, value: 1}, {label: 2, value: 2}];
This is the new element I wish to add to the existing array:
{label: 3, value: 3}
Below is the code snippet with the "push()" method implemented:
let arr = [{label: 1, value: 1}, {label: 2, value: 2}];
let newArr = arr.push({label: 3, value: 3});
console.log(newArr); // 3
However, it is worth noting that the "push()" method actually returns the length of the new array (which is "3" in this case) to the variable "newArr". My intention, on the other hand, is to obtain the updated array itself rather than just its length for the "newArr" variable. Are there any alternative methods to achieve this?