Question · JavaScript and TypeScript course · Module 5: Advanced JavaScript
Performance of Data Structure Operations
Which data structure operation is the fastest (O(1)) in JavaScript?
Answer options
- Sorting an array with sort()
- Searching for an element in an array with indexOf()
- Accessing an array element by index (array[0]) or an object property (obj.key)
- Iterating over all array elements with forEach()
You can check the correct answer by solving this task in the CodeWorlds game.