Split First name and Last name using javascript

I have a user with a name Paul Steve Panakkal. It's a long name it won't fit to the div container. So is there anyway to split first name and lastname from it using javascript or jquery.

The name is got from PHP into a variable in JavaScript. This is then splitted using JS.

Answers


You should use split method:

'Paul Steve Panakkal'.split(' '); // retutrns ["Paul", "Steve", "Panakkal"]

You can use it this way:

'Paul Steve Panakkal'.split(' ').slice(0, -1).join(' '); // returns "Paul Steve"
'Paul Steve Panakkal'.split(' ').slice(-1).join(' '); // returns "Panakkal"

So in common:

var firstName = fullName.split(' ').slice(0, -1).join(' ');
var lastName = fullName.split(' ').slice(-1).join(' ');

Need Your Help

How to stop a mp3 file from being downloaded by flash when in streaming mode

flash streaming

I have a flash player that has a set of songs loaded via an xml file.

Can IIS 6 serve requests for pages with no extensions?

iis

Is there any way in IIS to map requests to a particular URL with no extension to a given application.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.