Theory
Important array operations include traversal, insertion, deletion, searching and updating. Accessing an element by index is generally O(1), while searching an unsorted array can require O(n) time.
Example
const numbers = [10, 20, 30];
numbers.push(40);
numbers[1] = 25;
console.log(numbers);
Expected Output
The updated array is [10, 25, 30, 40].
Practice
Create an array and perform insertion, deletion and searching operations.
Interview Questions
- What are common array operations?
- What is array traversal?
- What is the complexity of accessing an array element?
- What is the complexity of linear search?