<div class="codetitle"> <span><a style="CURSOR: pointer" data="4389" class="copybut" id="copybut4389" onclick="doCopy('code4389')"><u>复代码</u></a></span> 代码如下:</div> <div class="codebody" id="code4389"> <br><html> <br><머리> <br><제목> JavaScript 배열 방법 확장 </title> <br><스크립트 언어="javascript"> <br><!-- <BR>Array.prototype.indexOf=function(substr,start){ <BR>var ta,rt,d=' '; <BR>if(start!=null){ta=this.slice(start);rt=start;}else{ta=this;rt=0;} <BR>var str=d ta.join(d) d ,t=str.indexOf(d substr d); <BR>if(t==-1)return -1;rt =str.slice(0,t).replace(/[^ ]/g,'').length; <BR>RT를 반환합니다. <BR>} <br><br>Array.prototype.lastIndexOf=function(substr,start){ <BR>var ta,rt,d=' '; <BR>if(start!=null){ta=this.slice(start);rt=start;}else{ta=this;rt=0;} <BR>ta=ta.reverse();var str= d ta.join(d) d,t=str.indexOf(d substr d); <BR>if(t==-1)return -1;rt =str.slice(t).replace(/[^ ]/g,'').length-2; <BR>RT를 반환합니다. <BR>} <br><br>Array.prototype.replace=function(reg,rpby){ <BR>var ta=this.slice(0),d=' '; <BR>var str=ta.join(d);str=str.replace(reg,rpby); <BR>str.split(d)를 반환합니다. <BR>} <br><br>Array.prototype.search=function(reg){ <BR>var ta=this.slice(0),d=' ',str=d ta.join(d) d, regstr=reg.toString(); <BR>reg=new RegExp(regstr.replace(//((.|n) )/.*/g,'\0$1\0'),regstr.slice(regstr.lastIndexOf('/') 1) ); <BR>t=str.search(reg);if(t==-1)return -1;return str.slice(0,t).replace(/[^ ]/g,'').length; <BR>} <br><br>window.onload=function(){ <BR>var a=new Array('aa1321321','b4323424b','cc345345','dd4654','dd4654','b4323424b' ); <BR>document.getElementById('t1').value=a.toString(); <BR>//document.getElementById('t2').value=a.indexOf('cc345345'); <BR>//document.getElementById('t3').value=a.lastIndexOf('dd4654'); <BR>document.getElementById('t4').value=a.replace('b4323424b','*');//把第一个b4323424b替换成* <BR>document.getElementById('t5').value =a.search(/dd4654/);//未找到返回-1 <BR>}; <BR>//--> <br></script> <br><style type="text/css"> <br><!-- <BR>입력{너비:600px} <BR>//--> <br></style> <br></head> <br><br><본문> <br><테이블> <br><tr><td>数组a:</td><td><input id="t1" type="text" /></td></tr> <br><tr><td>a.indexOf('cc345345'):</td><td><input id="t2" type="text" /></td> </tr> <br><tr><td>a.lastIndexOf('dd4654'):</td><td><input id="t3" type="text" /></td> </tr> <br><tr><td>a.replace(/d/g,'*'):</td><td><input id="t4" type="text" /> </td></tr> <br><tr><td>a.search(/dd4654/):</td><td><input id="t5" type="text" /></td> </tr> <br></테이블> <br></body> <br></html> <br> </div>