split string in two on given index and return both parts

前端 未结 8 2145
攒了一身酷
攒了一身酷 2020-12-05 12:33

I have a string that I need to split on a given index and then return both parts, seperated by a comma. For example:

string: 8211 = 8,211
        98700 = 98,         


        
8条回答
  •  再見小時候
    2020-12-05 13:01

    Try this

    function split_at_index(value, index)
    {
     return value.substring(0, index) + "," + value.substring(index);
    }
    
    console.log(split_at_index('3123124', 2));

提交回复
热议问题