CRM 2011 JS: Retrieve form all controls

//This is how to Retrieve form all controls using javascript in CRM 2011

//Retrieve all controls
Xrm.Page.ui.controls.forEach(function (control, index) {
    var attribute = control.getAttribute();
    if (attribute != null) {
        var attributeName = attribute.getName();
    }
});