I have this (sub)object called products.original.
which I then extract to a new object called productArray:
var productArray = [];
productArray = products.original;
/*some calculations here*/
//sort the object by lowest score
productArray.sort(function(a, b) {return a.score - b.score;});
Finally, I extract the first three cells in productArray to a third object called resultArray:
var resultArray= [];
resultArray = productArray.splice(0,3);
To my surprise, this reduces the length of products.original by 3 (the splice). Why? And what do I do to hinder this? Thanks in advance.
You did not copy the array, but just the reference to it. So all your operations are still performed on the original object.
For real cloning use slice.