Retrieve all elements of an array except the last one.
Features:
- Returns all elements except the last
- Returns empty array for single-element or empty arrays
- Handles arrays with any data type
- Simple and intuitive operation
- Uses lodash _.initial for reliable extraction
Examples:
- Input: [1, 2, 3] → Output: [1, 2]
- Input: ["a", "b", "c", "d"] → Output: ["a", "b", "c"]
- Input: [{id: 1}, {id: 2}, {id: 3}] → Output: [{id: 1}, {id: 2}]
- Input: [1] → Output: []
- Input: [] → Output: []
Use Cases:
- Data Preparation: Prepare data excluding the final element
- Validation: Validate all items except the last (e.g., footer data)
- Batch Processing: Process all but the last item
- Array Manipulation: Remove trailing elements