Home > Article > Web Front-end > js implements repeated splicing of multiple strings at the beginning and end
This article mainly shares with you js to realize the splicing of multiple strings with repeated start and end, string array, repeated start and end of strings, removal of repeated parts, and splicing. I hope it can help everyone.
var j=0; var isRepeat = null var index = null var res = new Array() var tmp_key2 var tmp_key1 var Repeat = function(ary) { var arr1 = tmp = ary; for(var i=0; i<ary.length; i++){ tmp_key1 = ary[i]; var len1 = tmp_key1.length; ccc: for(j = 0 ; j<arr1.length; j++){ if(i===j){ continue; } tmp_key2 = arr1[j]; var len2 = tmp_key2.length; index = -1; var index_num =0; for(var k = 0; k < len2; k++) { var tmp_str = tmp_key2.slice(0,k+1); index = tmp_key1.indexOf(tmp_str); if(index !== -1){ isRepeat = index; } if( isRepeat != null && index ===-1 ){ break ccc; } } } // console.log(isRepeat); if(isRepeat !== null) { res.push(tmp_key1.slice(0,isRepeat)+tmp_key2) } index = null; isRepeat = null; } console.log(res); return res; } var ary = new Array("中国红","红红火火","zhanglei","lei@silenc","kkkzhang"); Repeat(ary);rrree
The above is the detailed content of js implements repeated splicing of multiple strings at the beginning and end. For more information, please follow other related articles on the PHP Chinese website!