why a js map on an array modify the original array?
I'm quite confuse by the behaviour of map(). I have an array of objects like this : const products = [{ ..., 'productType' = 'premium', ... }, ...] and i'm passing this array to a function that should return the same array but with all product made free : [{ ..., 'productType' = 'free', ... }, ...] The function is : const freeProduct = function(products){ return products.map(x => x.productType = "free") } Which returns the following array : ["free", "free", ...] So i rewrote my function to be : const freeProduct = function(products){ return products.map(x => {x.productType = "free"; return x})