Home > other >  Output variables one by one from array
Output variables one by one from array

Time:01-28

how do I pull variables from array one by one? I want to make a card with one saying Zlin, second Praha, etc... The way it works now is that it outputs all of them at once 4x. Thank you.

   const KartyLoop = () => {
    var mesta = ['Zlin','Praha','Ostrava','Brno']
    var lokace = []
    for (var i=0; i < mesta.length; i  )
    {
        lokace  = mesta   "\n"
    }
return (<Text>{lokace}</Text>);
}

CodePudding user response:

Your code pushes the array itself and not its values. If I understand correctly you want to copy an array.

You would want to do this.

const KartyLoop = () => {
    var mesta = ['Zlin','Praha','Ostrava','Brno']
    var lokace = []
    for (var i=0; i < mesta.length; i  )
    {
        lokace  = mesta[i]   "\n"
    }
    return (lokace);
}
  •  Tags:  
  • Related