split() method cannot be used on date

When working with a string that contains a date in the format 'DD-MM-YYYY' and wanting to change it to 'DD/MM/YYY', it is common practice to use the split method for formatting.

The split method successfully separates the string and formats the date as desired, which seems to work fine initially.

However, an issue arises when an error is thrown indicating that .split() is not a function.

Attempts to troubleshoot by changing the method to multiline for debugging purposes and confirming the data type of the string being split show that the variable is indeed a string, yet the same error persists.

formatDate(date) {
  if (!date) return null
  const [year, month, day] = date.split('-')
  return `${day}/${month}/${year}`
}

The formatDate function expects a string argument like ('29-09-2018').

Expected:

To format the 'date' without encountering any errors in the console.

Actual:

Although the 'date' is formatted, an error message appears:

vue.runtime.esm.js?2b0e:1888 TypeError: date.split is not a 
function

Answer №1

I have discovered a solution.

Upon careful analysis of my question, it is clear that the string is being split and the date within it is being formatted. The error is actually coming from Vue itself.

Despite the controversial nature of my query (as evidenced by the down votes), the issue still remains unresolved.

To address this problem, I implemented the following:

computed: {
  dateFormatted() {
    this.formatDate(this.startDate.toString())
  }
 }

Interestingly, 'this.startDate' is initially a string and even after being passed to 'formatDate()', it remains as a string. This discrepancy is likely causing the issue to arise.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

switching the content of a button when it is clicked

I am currently using Angular 7 and I am trying to achieve a functionality where the text on a button changes every time it is clicked, toggling between 'login' and 'logout'. Below is the code snippet I have been working on: typescript ...

store picture in a database: ServiceNow

When filling out a form, I often copy and paste images from webpages into a journal field. However, these images end up being saved as references to the original webpage. Is there a method to save these images directly to the form or record instead? ...

Leveraging Vue mixin within a @Component

After implementing the vue-property-decorator package, I encountered an issue when trying to use a mixin method inside the beforeRouteEnter hook. Here is what I initially tried: import { Component, Mixins } from 'vue-property-decorator'; import ...

AWS: Grant access to designated clients for users

My AWS Cognito setup includes: AWS Cognito User Pool: UserPool_1 The User Pool contains 3 users: Mike, Sarah, John I have configured 3 App Clients under this user pool: WebClient_1 WebClient_2 WebClient_3 I need Mike to be able to access: WebClient_ ...

Electron: Interactive menu customization

Is there a way in Electron to dynamically enable/disable specific MenuItem in the context menu based on the element that the user right-clicks on? Additionally, I am looking for a method to identify the exact element clicked and pass that information to th ...

Insert a zero in front of any single digit hour

What is the best way to add a leading zero before single digit numbers in time format? For example, how can we convert "0:3:25" (hh:mm:ss) to "00:03:25"? ...

Finding the identifier for resources through excluding external influences

I am currently facing an issue with the full calendar plugin. In my set up, I have 3 resources along with some external events. The problem arises when I try to drop an external event onto the calendar - I want to retrieve the resource id from which the ev ...

Tips for converting a select option into a button

Currently, I am working with Laravel to develop my shopping cart. My goal is to implement a feature that allows customers to select the quantity of a product and have the price update accordingly when they click on a specific number. However, I am facing a ...

What could be the reason behind the failure of JSON.stringify() on this particular array?

I am encountering an issue with an array that I have declared like this: array = []; The array contains values that look like this - .... ChIJOaegwbTHwoARg7zN_9nq5Uc:"ChIJOaegwbTHwoARg7zN_9nq5Uc" ChIJXTwCdefHwoAR9Jr4-le12q4:"ChIJXTwCdefHwoAR9Jr4-le12q4 ...

Is there a method for verifying the application signature in Ionic?

For the past 2 days, I've been on a quest to find information about app certificate validation libraries/functions in Ionic. After discovering SignatureCheck.java for Android (link: enter link description here), I wonder if there is a similar solution ...

Turn off pagination for tables in Material-UI

Currently, I am utilizing the TablePagination component from Material-UI in my React project. Unfortunately, this component does not come with a built-in disabled prop. I do have a boolean variable called loading that I would like to utilize as a paramet ...

Adjusting Countdown.js functionality

I stumbled upon countdown.js after coming across this helpful resource: My knowledge in JavaScript is limited, and I'm looking to configure the countdown to start exactly a week from today, which would be on February 24, 2014. Is there a way to twea ...

What is the process of modifying the data in DataTables once it has already been initialized?

I am looking to dynamically populate a table using datatables through an ajax request. Here is the approach I have taken: $(function(e) { $('#CampaignMenu').change(function(e) { $('#ReportWrapper').hide(); ...

Ways to update modal content upon clicking a button

I have a scenario where I need to display 2 modals (box1 and box2) in my code with box2 appearing on top of box1. Each modal has its own button, and I want to make sure that box1 appears first. Then, when the user clicks the button in box1, it transitions ...

I'm getting an error on the console saying that the activator slot needs to be bound, even though I have already bound it. What could

I am trying to showcase this content as a dialog box within another page. The code snippet can be found on https://www.youtube.com/watch?v=J4fIObUYiHw&list=PL4cUxeGkcC9g0MQZfHwKcuB0Yswgb3gA5&index=23. While it works for the creator, I am encounte ...

Changing the color of the Bootstrap-Vue b-dropdown button when it is open

When it comes to customizing the button color and hover effect, the code below does the job perfectly. However, there seems to be an issue where the button color reverts back to gray when the menu is open and the cursor moves away from the button. How can ...

To identify the dynamically inserted and generated div element amidst the other elements on the page

My goal is to have a new div generated and inserted over the other elements on the page when a button is clicked. Here is the markup I've written: <div id="parent"> <div id="d1"> </div> <div id="d2"> </div&g ...

The problem with THREE JS OcclusionComposer: encountering "Cannot read properties of undefined (reading 'x')" error

I am attempting to replicate the Volumetric Lighting demonstration created by JMSWRNR but I am encountering difficulties with the Occlusion Composer. Since I am not well-versed in GLSL, debugging has proven to be quite challenging, especially for someone l ...

What is the best way to save the properties of elements in an array of objects within another array?

I have obtained attributes from objects within an array that I need to store in another array. Here is the data I am working with: https://i.sstatic.net/b0JtY.jpg My goal is to extract the `displays` name attribute and save it in the `opt[]` array, which ...

Using HTML, jQuery, and JSON with an AJAX call to populate two web tables stacked on top of each other

I am encountering an issue with populating two tables using two searches based on user input in mySQL-JSON-AJAX. When the user enters a search term and clicks the corresponding button, data should populate the respective table. The problem arises when clic ...