I am doing check on three different variables which are holding array of strings like below.
var a = ["ghi",dwe"]
var b = ["ghsj"]
var c = ["gdjr"]
var result; // result array
I am checking each time if variable a,b,c are not undefined and if they are holding some value I am simply pushing a string for each variable in the result array.
Below is line of code for same.
if(a !== undefined && a.length > 0) {
result.push("Astring");
}
if(b !== undefined && b.length > 0) {
result.push("Bstring");
}
if(c!== undefined && c.length > 0) {
result.push("Cstring");
}
Expected Result should be if the var a,b,c are defined and non empty then result array variable should hold value like below
["Astring","BString","CString"]
Is there a more efficient way of describing this code.Here I am just checking each and every variable using if condition. Also , I am restricted in some ways as I am using a Rhino js engine ver 1.7.12.