Sinan Samet Sinan Samet - 1 month ago 13
React JSX Question

Looping through styles with map function

I am trying to loop through styles with the map function but it returns the numbers 83 to 90 instead why does this happen?

let stylesArray = [styles.punt1, styles.punt2,
styles.punt3, styles.punt4,
styles.punt5, styles.punt6,
styles.punt7, styles.punt8
]

{stylesArray.map(function(object, i){
console.log(object);
<TouchableHighlight onPress={openQuestionOverview} style={[styles.punt, object]}>
<Image source={vraag1} />
</TouchableHighlight>
})}

Answer

You need to return the map result:

let stylesArray = [styles.punt1, styles.punt2, 
                   styles.punt3, styles.punt4, 
                   styles.punt5, styles.punt6, 
                   styles.punt7, styles.punt8
                  ]

 {stylesArray.map(function(object, i){
    console.log(object);
    return (
        <TouchableHighlight onPress={openQuestionOverview} style={[styles.punt, object]}>
            <Image source={vraag1} />
        </TouchableHighlight>
    )
 })}

You also don't use the result of the mapping step.