I know what is the difference between unshift()
and push()
methods in JavaScript, but I'm wondering what is the difference in time complexity?
I suppose for push()
method is O(1) because you're just adding an item to the end of array, but I'm not sure for unshift()
method, because, I suppose you must "move" all the other existing elements forward and I suppose that is O(log n) or O(n)?