Skip to content

Waldo: Search the JavaScript Object Model in under 1 KB

Updated: at 08:07 PM

Have you ever needed to find a property or value buried in the catacombs of your JavaScript objects? Waldo to the rescue!

Here’s a tiny util that you can save as a bookmarklet and use to crawl the JavaScript object model of any web site. Waldo (thanks to @shinypb for the name!) lets you find and inspect instances by name, type or value, and it can be easily customized to add additional tests. It runs in the console on Chrome, Firefox, Safari and IE>8. It’s sourced on github. Feel free to fork it if you want to add more search methods or a spiffy UI.

Loading the Waldo script will create a global object called find which invokes a set of utility methods: byName, byNameContains, byType, byValue, byValueCoerced and custom. Each method will crawl the entire runtime JavaScript model from window down (unless otherwise specified) and report every object that matches the search term argument. There is also an optional options argument for specifying a) the root object for the search and b) the root of the object path that will display in the search results (the latter option is purely cosmetic).

Read more from the source: JavaScript, JavaScript…