Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8084311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:45:20+00:00 2026-06-05T17:45:20+00:00

how to split an array index i.e.. sample code var parts = currentVal.split( );

  • 0

how to split an array index i.e.. sample code

var parts = currentVal.split(" ");
var datePart = parts.splice(0,1);
alert("Date: " + datePart );
var timePart = parts.join(' ');

here i am validating the date time regular expression. var datePart is an array index, now i want to split datepart ….

var parts1 = datePart.split('/');
parts1.date = parseInt(parts1[0]);
parts1.month = parseInt(parts1[1]);
parts1.year = parseInt(parts1[2]);  

but it is showing uncaught type error, their is no method split(); Can any one help me how do i separate date, month, year.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:45:21+00:00Added an answer on June 5, 2026 at 5:45 pm

    If you’re trying to just check whether a string represents a valid date or not, I would personally recommend the magical Date object that javascript natively supports. Through some sort of wizardry it can read the date in almost any format you throw at it, and if it is an invalid date it will evaluate to the string Invalid Date.

    So to check if currentVal is a valid date, do:

    if (new Date(currentVal) == 'Invalid Date') {
        ... // The date is invalid
    } else {
        ... // The date is valid
    }
    

    On the other hand, if you need to use a specific regex to validate the date, you could either do something like

    var parts = currentVal.split(' ');
    var dateParts = parts[0].split('/');
    var timePart = parts[1]; // Maybe you want to split this as well?
    

    And this would leave dateParts as an array containing the month, day and year.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a <pre> & <code> tag which looks like: <pre><code>somevar = array.join("-") somevar.split("-")
I am trying to split an array into n parts. Sometimes these parts are
Here is my JavaScript code so far: var linkElement = document.getElementById(BackButton); var loc_array =
I need to split my string input into an array at the commas. Is
Trying to split this string 主楼怎么走 into separate characters (I need an array) using
In C# I need to split a string (a log4j log file) into array
How can I take a multi-dimensional array like the below, and split it into
I am trying to send the result of a split() function into an array
I'm using authorize.net AIM, the sample code they provide prints an ordered list of
Given the following string: var str = one,two,three; If I split the string on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.