废话不多说上代码!!!
const ary = [1,2,3,4]
Array.prototype.myjoin = function(flag){
let str = ''
this.forEach((item,index)=>{
if(index+1 != this.length){
str += item + flag
}else{
str += item
}
})
return str
}
console.log(ary.join(','))
console.log(ary.myjoin(''))
String.prototype.mySplit = function(tag){
let str = this + tag
let arr = []
let num = str.indexOf(tag)
while(num > -1){
if(str.substring(0,num)){
arr.push(str.substring(0,num));
}
str = str.substring(num+1,str.length)
num = str.indexOf(tag)
}
return arr
}
let str = '1,2,3,4,5,889,556,447,221,'
console.log(str.mySplit(','))