Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  167] [ 2]  / answers: 1 / hits: 7397  / 10 Years ago, tue, october 7, 2014, 12:00:00

I am trying to display only First and Last name. Sometimes there will be a middle name comes. In that case i need remove the middle name and join first and last name.How is it possible using JavaScript.
The name comes to a variable from database like



var displayname=abc pqr xyz


i just need abc xyz to a variable .
Thanks in advance


More From » jquery

 Answers
8

You could split on white space and take the first and last element of the array.



var displayname = abc pqr xyz;
var tmp = displayname.split( );
displayname = tmp[0] + + tmp[tmp.length-1];

[#42051] Sunday, October 5, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
muhammadbrandend

Total Points: 670
Total Questions: 95
Total Answers: 97

Location: Saint Vincent and the Grenadines
Member since Sat, Sep 11, 2021
3 Years ago
;