How to split a string at the first `/` (slash) and surround part of it in a ``?

前端 未结 7 1746
独厮守ぢ
独厮守ぢ 2020-11-28 01:28

I want to format this date:

23/05/2013
.

First I want to split the string at the first / and have the res

7条回答
  •  感情败类
    2020-11-28 02:17

    var str = "How are you doing today?";
    
    var res = str.split(" ");
    

    Here the variable "res" is kind of array.

    You can also take this explicity by declaring it as

    var res[]= str.split(" ");
    

    Now you can access the individual words of the array. Suppose you want to access the third element of the array you can use it by indexing array elements.

    var FirstElement= res[0];
    

    Now the variable FirstElement contains the value 'How'

提交回复
热议问题