An analytics transformation should prepare the values a report needs without changing the application data behind them. Creating a new array does not, by itself, guarantee that separation. Consider a hypothetical catalogue. The reporting convention groups category labels without regard to letter case or surrounding whitespace. Product IDs must remain exact.
Decide which text may change
A category such as Guides can have an agreed reporting form, guides. An ID such as 0072 is an identifier, not a quantity. Preserve its leading zeros, punctuation and letter case. Apply a transformation only to fields whose meaning permits it. Lowercasing every string can combine distinct identifiers.
String methods return values that you must use. trim() removes whitespace at the ends; it does not remove spaces inside a label. Calling it without storing or returning the result leaves the original field unchanged. Assigning the result back to item.item_category changes the object property, even though strings themselves are immutable.
A new array can still share its objects
Assigning items to another variable does not copy the array. Both variables refer to the same array. slice() creates a new array, but the copy is shallow. When an entry is an object, both arrays still refer to that object. Editing a property through either array affects the shared object.
filter() also returns a shallow selection. map() creates a new array from callback results. Neither method prevents the callback from changing the original objects. A callback that assigns item.item_category and then returns item keeps that shared reference. The new array is not proof that the source is unchanged.
