String split and get first and last occurrences

前端 未结 4 657
渐次进展
渐次进展 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:20

    If you're really getting a performance problem from the large array (dont' optimize prematurely), you could use slice to extract the single strings and indexOf/lastIndexOf to find their positions:

    str.slice(0, str.indexOf(','))
    and
    str.slice(str.lastIndexOf(',')+1) // 1==','.length
    

提交回复
热议问题