What is the time complexity of the unshift() method in JavaScript arrays?
- O(n)
- O(1)
- O(log n)
- O(n log n)
The unshift() method in JavaScript arrays has a time complexity of O(n), where "n" represents the number of elements in the array. This is because it needs to shift all existing elements to make room for the new element at the beginning. The higher the number of elements, the longer it takes.
Loading...
Related Quiz
- When using a do-while loop, the loop will always execute at least ________ time(s).
- How does the await keyword manage the Promise’s resolve value?
- How does JavaScript implement inheritance internally?
- To change the content of an HTML element, you can use textContent or _________.
- The _________ method is used to bind an object context to a function and is called immediately.