I'm interested in finding a high-performance method for removing and storing elements from an array. My goal is to create an object pool that minimizes the need for garbage collection calls.
Similar to how .pop()
and .unshift()
remove elements from an array and return their values, I want to remove an element at a certain index, store its value in a variable, and avoid generating unnecessary arrays or objects.
.splice()
effectively removes the element at a specified index and stores the value in an array. While I can access it, the function itself generates a new array, which can lead to garbage collection in the long run.
.slice()
faces the same issue, as it creates a new array as well.
Is there a method to extract and store a specific indexed element without the need for creating a new array?