Reputation: 375
const arr = ['name', 'contact number']
const App = () => (
<div style={styles}>
Add {arr.split(',').map(o=>o)}
</div>
);
why this won't work? I want to print Add name & contact, but stuck at splitting it.
Upvotes: 0
Views: 2247
Reputation: 2561
You are looking to join the values
Add {arr.join(',')}
Below links should help you
Upvotes: 2
Reputation: 27811
You're using 2 functions wrong:
split
is supposed to be used to split a string into an array, around the provided character. You already have the resulting array..map(o=>o)
is useless - it basically returns the same array provided.You're probably looking to do this Add {arr.join(' & ')}
.
Upvotes: 1
Reputation: 20885
There is nothing to split. I think you are trying to join them:
const arr = ['name', 'contact number']
const App = () => (
<div style={styles}>
Add {arr.join(',')}
</div>
);
Upvotes: 1