How to extract a substring using substr in JavaScript

How to extract a substring using substr in JavaScript

File name handling with substr simplifies extraction of file extensions and fixed-width tokens from logs. Using lastIndexOf with substr efficiently retrieves components without pre-calculation. Negative indices and a safe wrapper enhance usability, preventing out-of-bounds errors. Substr truncates decimal parameters, allowing seamless handling of float-based lengths.