Whenever I try to assign arrays, a problem arises:
var arr = [ {'id': 1, 'size': 'large' }, {'id':4, 'size': 'small'} ];
function adjust(a){
var result=[{'id': 1, 'size': 'large'}];
a=result.slice();
}
adjust(arr);
document.write("result:" + JSON.stringify(arr)); //arr contains both 'large and small'
I wish to populate 'arr' with the data from the 'result' array, but this method doesn't seem to work. However, it is possible to clear the array and update its content in this manner:
a.length=0;//arr is now empty outside of the function
a[1].id = 100;//changing id value outside of the function
I am aware that I could achieve this by returning the 'result' array and assigning it externally to 'arr', but there will be many such connections within the function. Any guidance on resolving this issue would be highly appreciated. Thank you