Having a problem with managing a jQuery array.
My goal is to create two distinct arrays.
var main_array = []
function initialize_arrays(){
main_array[0] = {id: 1, status: true, number: 10};
main_array[1] = {id: 1, status: true, number: 16};
main_array[2] = {id: 1, status: true, number: 20};
}
function adjust_number(array, index, new_number){
array[index].number = new_number
}
initialize_arrays()
new_array = adjust_number(main_array, 0, 20);
console.log(main_array)
The issue I'm facing is that when I try to modify an element in the $main_array and create a new array, the original main_array also gets changed.
I specifically want to avoid changing the numbers in the main_array.
I'm having difficulty figuring out what might be going wrong here.