Thanks Andrew & LeoAlt, both the solutions are correct!
Here is the updated code that I've used:
function writebooleanfieldlables(executionContext){
debugger;
var attfldlst1 =[];
var outpt;
var formContext = executionContext.getFormContext();
var selectedfieldnames=[];
formContext.data.entity.attributes.forEach(
function(attribute,index){
if(attribute.getAttributeType() =="boolean"){
attfldlst1.push(attribute.getName());
}
}
);
attfldlst1.forEach(
function(attribute,index){
if(formContext.getAttribute(attribute).getValue() == 1 && formContext.getAttribute(attribute).getValue() != null){
selectedfieldnames.push(formContext.getControl(attribute).getLabel())
}
}
);
formContext.getAttribute("new_selectedfields").setValue(selectedfieldnames.join(','));
}