Join Array from startIndex to endIndex

后端 未结 2 373
深忆病人
深忆病人 2021-01-11 10:52

I wanted to ask if there is some kind of utility function which offers array joining while providing an index. Maybe Prototype of jQuery provides this, if not, I will write

2条回答
  •  天涯浪人
    2021-01-11 11:53

    Just slice the array you want out, then join it manually.

    var array= ["a", "b", "c", "d"];
    var joinedArray = array.slice(1, 3).join("-");
    

    Note: slice() doesn't include the last index specified, so (1, 3) is equivalent to (1, 2).

提交回复
热议问题