Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

breaking up a string in jQuery

I have this string...

var myDate = "November 15, 2010";

.....and I need to do this...

$("#request_showdate_1i").val('2010');
$("#request_showdate_2i").val('November');
$("#request_showdate_3i").val('15');

Any ideas how to break this string up?

like image 944
Matt Elhotiby Avatar asked Dec 22 '22 22:12

Matt Elhotiby


1 Answers

You can for example use a regular expression:

var parts = /(\S+) (\d+), (\d+)/.exec(myDate);
$("#request_showdate_1i").val(parts[3]);
$("#request_showdate_2i").val(parts[1]);
$("#request_showdate_3i").val(parts[2]);
like image 147
Guffa Avatar answered Jan 04 '23 16:01

Guffa