var str="2018-11-01";
var newstr = str.split('-').reverse().join('/');
console.log(newstr);
The method split()
splits a String object into an array of strings by separating the string into substrings
The method reverse()
inverts the entries of an array. The first element of the array becomes the last and the last becomes the first.
The method join()
joins all elements of an array into a string and returns this string.
If the separator in the method join()
is omitted array elements are separated with a comma (","). If the separator is an empty string, all elements are joined with no character between them
About your comment
como eu faço para a data ir parar ai dentro desse parênteses sendo que
ela está digitada em um input do formulário?
With a Javascript function
function myFunction() {
var str=document.getElementById("data1").value;
console.log(str);
var newstr = str.split('-').reverse().join('/');
console.log(newstr);
}
<input required type='date' name="data1" id="data1" class="form-control" />
<button onclick="myFunction()">Submit</button>
With Jquery
The focusout event is triggered as soon as the element loses focus
var str = $("#data1");
str.focusout( function(){
//data retornada do input
console.log(str.val());
//data transformada
console.log(str.val().split('-').reverse().join('/'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input required type='date' name="data1" id="data1" class="form-control" />
https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta
– user76097