Making an array immutable

Let’s say, I have a requirement of making an array immutable(no one can modify). Usually, when passing an array to a function as an input, it is passed by reference, not by value. So the function can change or alter its value instead of just using it.

A simple trick would be to freeze the array using Object.freeze


Leave a Reply

Your email address will not be published. Required fields are marked *