It's probably not safe to rely on the widget's html file name to find out the widget's id. It might be better to build a mapping object in the loop above, and use _.keys or _.values to get the paths array.