I was wondering if is possible to transform a string into an array using Arrow Function:
var str = 'Bob@example.com;Mark@example.com,robert@email.com';
var result = str.split(';').map(e => e.split(','))
//desired result: {VALUE: 'Bob@example.com'},
// {VALUE: 'Mark@example.com},
// {VALUE: 'robert@email.com'}
You could split with a character class of comma and semicolon and map objects.
const str = 'Bob@example.com;Mark@example.com,robert@email.com', result = str .split(/[,;]/) .map(VALUE => ({ VALUE })); console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
You could use a regular expression to handle this
var str = 'Bob@example.com;Mark@example.com,robert@email.com'; var result = str.split(/[;,]/) console.log(result);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.