Migrating lodash / underscore in AngularJS code to modern Angular
AngularJS apps often loaded lodash or underscore as a global _ (sometimes injected as a constant) and used it for collections, cloning and debouncing, alongside helpers such as angular.copy, angular.extend and angular.forEach.
What replaces it
| Option | When to choose it |
|---|---|
| Native JavaScript | map, filter, find, flatMap, Object.entries, structuredClone and optional chaining cover most everyday calls. |
| lodash-es with named imports | Keep the functions that have no simple native equivalent (debounce, isEqual, orderBy) and let the bundler drop the rest. |
| es-toolkit | A newer, smaller utility library with a lodash-like API, if you want to leave lodash entirely. |
How to migrate it
- Count which functions are really used; a search for _. usually shows a short list.
- Replace the global with ES imports in the files you migrate, and use native methods where they read as clearly.
- Replace angular.copy, angular.equals and angular.forEach too; they disappear together with AngularJS.
Watch out. Watch the functions that mutate, such as _.merge, _.remove and _.pull. With signals and OnPush change detection, changing an array or object in place does not update the view.
Other libraries
Planning a migration or a micro-frontend platform?
In a 20-minute call you describe your situation and I tell you how I'd approach it. If it isn't worth doing yet, I'll say so.
Message me on LinkedIn