user2004
user2004

Reputation: 1973

display different string in UI

I have a string in this format

strb= str1+ ' ' + str2

  <span>{{strb}}</span>

How can I change this to display it backwards

Upvotes: 1

Views: 93

Answers (1)

Lu&#239;s
Lu&#239;s

Reputation: 2843

You can split your string at , to get first name and last name separately. This will literally cut away the parts you pass as a prop to your .split() function and return an array with the leftover pieces of your string.

const names = fullName.split(', '); //['BROWN', 'MARY'];
const firstName = names[1]; //'MARY'
const lastName = names[0]; //'BROWN'

Upvotes: 2

Related Questions