How to use map plus slice() to intercept an array

js interception array

在实现需求的时候遇到一个需要展示时段为:12:30-14:30
insert image description here

For example: the interface returns fields in this form
insert image description here
, which requires JSON.parse() to convert to a normal array structure

const time = JSON.parse(item.frameTime)

Then, use slice() of js to intercept

const _frameTime = time.map((item) => {
    
    
        return item.slice(0, 5)
      })

Finally, use join('-') to replace the "," in the array

const frameTime = _frameTime.join('-')

Guess you like

Origin blog.csdn.net/qq_50851509/article/details/130388141