Reputation: 91
function openmodal(modalarray) {
return Alert.alert(
"Alert Title",
"My Alert Msg",
[
modalarray.forEach(element => {
"{text: element, onPress: () => console.log('button press)},";
})
],
{ cancelable: false }
);
}
Upvotes: 2
Views: 1139
Reputation: 51
Try:
function openmodal(modalarray) {
return Alert.alert(
"Alert Title",
"My Alert Msg",
modalarray.map(element => ({
text: element,
onPress: () => console.log('button press')
})),
{ cancelable: false }
);
}
Upvotes: 1
Reputation: 5023
Please use .map
function instead of .forEach
. .forEach
doesn't return any value, hence you are just passing undefined
in the array.
Consider the following example
function openmodal(modalarray) {
return Alert.alert(
"Alert Title",
"My Alert Msg",
[
...modalarray.map(element =>
({text: element, onPress: () => console.log('button press')}))
],
{ cancelable: false }
);
}
Hope this will help!
Upvotes: 2