CoffeeScript: capture first word in string

- 1 answer

Ad

I have an input field with the idpost_date.

The value entered in this field is a date: it can vary, of course, but it always uses the same structure:

Monday, November 30 2015 05:55 PM
Tuesday, December 01 2016 05:55 AM
Wednesday, December 02 2015 05:55 PM

I need to capture the day in this date, ie: the first word of the string.

How can I do that with CoffeeScript?

Ad

Answer

Ad

If there is always a comma, use it to split and get first value :

date = "Monday, November 30 2015 05:55 PM"
alert(date.split(",")[0])

if all dates are in the same string, first split with "\n" then take each string to get day with ","

Ad
source: stackoverflow.com
Ad