{"library":"lodash.last","title":"lodash.last","description":"lodash.last provides a focused, modularized implementation of the `_.last` function from the Lodash utility library. It is designed to retrieve the last element of an array, returning `undefined` for empty arrays. As part of the extensive Lodash ecosystem, `lodash.last` adheres to semantic versioning, with its versioning generally aligning with major Lodash releases. The current stable version of the main Lodash library is 4.17.x, and modular packages like `lodash.last` typically follow this major version, ensuring compatibility. Lodash itself maintains a consistent release cadence for bug fixes and security patches within its v4 series. A key differentiator for modular Lodash functions like `lodash.last` is the ability to import only the necessary utilities, which can significantly aid in reducing application bundle sizes compared to importing the entire `lodash` library, particularly in modern JavaScript environments that leverage tree-shaking.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install lodash.last"],"cli":null},"imports":["const last = require('lodash.last');","import last from 'lodash.last';","import last from 'lodash.last';\nconst data: number[] = [1, 2, 3];\nconst lastElement: number | undefined = last(data);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import last from 'lodash.last';\n\nconst numbers: number[] = [1, 2, 3, 4, 5];\nconst lastNumber: number | undefined = last(numbers);\nconsole.log(`The last number is: ${lastNumber}`);\n// Expected output: The last number is: 5\n\nconst emptyArray: any[] = [];\nconst lastOfEmpty: any | undefined = last(emptyArray);\nconsole.log(`The last element of an empty array is: ${lastOfEmpty}`);\n// Expected output: The last element of an empty array is: undefined\n\nconst mixedArray = [1, 'hello', true, { key: 'value' }];\nconst lastMixedElement: any | undefined = last(mixedArray);\nconsole.log(`The last element of a mixed array is: ${lastMixedElement?.key ?? String(lastMixedElement)}`);\n// Expected output: The last element of a mixed array is: value (if object, else its string representation)","lang":"typescript","description":"Demonstrates how to import and use the `last` function to retrieve the final element from various arrays, including handling empty arrays and showing type inference in TypeScript.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}