Well, you could do this:
objResponse = {
type : evl_ResponseType[arrResponse[0]].name;
};
if(arrResponse.length>2){
objResponse.partition = evl_Partition_Status_Code[arrResponse[1]].description;
objResponse.icons = iconLED(bin(arrResponse[2]).result);
objResponse.numeric = arrResponse[3];
objResponse.beeps = BEEP_field[arrResponse[4]];
objResponse.msg = arrResponse[5].replace('$','').trim();
}
return objResponse;
But I don't think I'd call it more elegant.
If you don't mind the properties existing even when they don't have useful values, you could do this:
objResponse = {
type : evl_ResponseType[arrResponse[0]].name;
partition : arrResponse.length>2 && evl_Partition_Status_Code[arrResponse[1]].description,
icons : arrResponse.length>2 && iconLED(bin(arrResponse[2]).result),
numeric : arrResponse.length>2 && arrResponse[3],
beeps : arrResponse.length>2 && BEEP_field[arrResponse[4]],
msg : arrResponse.length>2 && arrResponse[5].replace('$','').trim()
};
return objResponse;
The properties will have the value false if the condition prefixing them isn't met.
That also has the advantage that you can tailor the conditions to the index you're using (e.g., using arrResponse.length > 5 when you're going to use arrResponse[5] for msg).
Side note: Your code wasn't assigning to partition if arrResponse.length was not >2, but the value you're assigning to partition is there even if arrResponse.length equals 2.
evl_objects are dictionaries, andarrResponsecontains keys into that dictionary which are being used to look up the actual values you want to hang on to?