+ Start a Discussion
Rama_SFDCRama_SFDC 

for loop not working in lightning js controller


Hi ,
how to iterate all the value in for loop , but below code has been ovverite old values and latest values printing , how to avoid overrite in for loop ?

var strgrpname = event.getParam("strgroupname");  ex: first time "Test1" , second time "Test2" , third time "Test3"
var strname = [];
         for(var strbal  in strgrpname ){
          strname .push(strbal);      
        } 
component.set("v.name",strname ) ;
console.log('pirnt-->'+component.get("v.name" )); result : Test3 .
RazaRaza
Hi Ramakrishana
please try this code
var strgrpname =event.getParam( "strgroupname");
var strname=[];
for each (var item in strgrpname){
   strname.push(item);
}
component.set("v.name",strname);
if this answer is useful for you please choose best answer
let me know if any hlep you regading this code:

Thanks
RAZA