String split and get first and last occurrences

前端 未结 4 678
渐次进展
渐次进展 2021-01-11 13:28

I have a long string of ISO dates:

var str = \"\'2012-11-10T00:00:00.000Z\', \'2012-11-11T00:00:00.000Z\', ****  \'2013-11-12T00:00:00.000Z\'\";
4条回答
  •  [愿得一人]
    2021-01-11 14:32

    It's really not a waste of space, since Javascript is barely taking up any memory on the computer. Unless the string is gigabytes long, I wouldn't worry about it. To get the first and last, just do this:

    arr=str.split(',');
    var first=arr.shift(); //or arr[arr.length-1];
    var last=arr.pop(); //or arr[0];
    

提交回复
热议问题