last¶
The 'last' filter is designed to retrieve the last element of an array or string.
Functionality
- Arrays: If the input value is an array, the
lastfilter returns the last element of that array. - Strings: If the input value is a string, the
lastfilter returns the last character of that string.
Syntax
ArgumentsThe last filter does not require any arguments.
Code Samples
Example 1: Last Element of an Array
Output:
Example 2: Last Character of a String Output:Outliers and Special Cases¶
- Empty Arrays: If the input array is empty, the
lastfilter returnsnull. - Empty Strings: If the input string is empty, the
lastfilter returnsnull. - Non-Array/String Input: If the input is neither an array nor a string, the
lastfilter returns the original input value unchanged.
Key Points¶
- The
lastfilter is a simple and convenient way to access the final element of a sequence. - It gracefully handles both arrays and strings.
- It is particularly useful when you need to extract a specific piece of information from the end of your data.