0

I have my string like this:

selectedDates: 06/15/2015,06/14/2015,06/12/2015,06/10/2015,06/09/2015

and I would like to have these dates in an array of strings.

When I do var selectedDatesArray = selectedDates.split(",");

I am getting this error:

TypeError: selectedDates.split is not a function

What am I missing? This part of the code is in angularjs's controller.

10
  • How is selectedDates defined? I see a colon in the declaration. is selectedDates part of a json object? Commented Jun 15, 2015 at 14:11
  • selectedDates is a string that has dates seperated by a comma. Commented Jun 15, 2015 at 14:13
  • But why is there a colon in the declaration? Is it part of a json object? If yes then you will have to do thatObject.selectedDates.split(","). And also, there is no quotes around the string. Commented Jun 15, 2015 at 14:14
  • that colon is got in there because I had it in my console.log like this console.log('in updateScreen self.selectedDates: '+ self.selectedDates); Commented Jun 15, 2015 at 14:16
  • Try your code in Chrome's console and you should see what the problem is. Commented Jun 15, 2015 at 14:16

1 Answer 1

1

please try this code:

var myStr = '06/15/2015,06/14/2015,06/12/2015,06/10/2015,06/09/2015 ';
var splitArr = myStr.split(',');

this should work for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.