var arr = ["134228.434-145343.386","134190.007-145355.928","134151.912-145368.525"] function test(val){ let start = arr.indexOf(val[0]); let end = arr.indexOf(val[1]); if(start=!'-1'&&end!='-1'){ return '' } for(let i=0;i<val.length-1;i++){ // 起点存在, // 在数组指定位置插入 if(start!='-1'){ arr.splice(start,0,val[1]); } // 终点存在, if(end!='-1'){ arr.splice(end,0,val[0]); } } console.log(arr) } test(["134190.007-145555.928","134151.912-145368.525"])