JS数组去重: 已知数组 var array=[1,1,2,3,4,6,6,7,8,8,9],如

2020-10-29 教育 64阅读


我的第一个网页</title><br /><script language="javascript" type="text/javascript"><br />function show(){<br /> var array=[1,1,2,3,4,6,6,7,8,8,9];<br />var count = 0;<br /> for(var i=0;i<array.length;i++){<br /> if(i==array.length-1){<br /> document.getElementById("arr").value+=array[i].toString();<br /> }else{<br /> document.getElementById("arr").value+=array[i].toString()+",";<br /> }<br />}<br />for(var k=0;k<array.length;k++){<br /> if(array[k]!=array[k+1]){<br />count++;<br />} <br />}<br />for(var j=0;j<array.length;j++){<br /> if(j==array.length-1){<br />if(array[j]!=array[j+1]){<br /> document.getElementById("newArr").value+=array[j].toString();<br />}<br /> }else{<br />if(array[j]!=array[j+1]){<br /> document.getElementById("newArr").value+=array[j].toString()+",";<br />}<br /> }<br />}<br /> }<br /></script><br /></head><br /><body onload="show()"><br /><table width="314"><br /> <tr><br /> <td width="80">原数组:</td><br /> <td width="224"><input name="arr" type="text" id="arr" readonly="readonly" /></td><br /> </tr><br /> <tr><br /> <td>新数组:</td><br /> <td><input name="newArr" type="text" id="newArr" readonly="readonly" /></td><br /> </tr><br /></table><br /></body><br /></html> </div> <div class="tags"> </div> <div class="clear"> <div class="shares"> <b>声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com</b> <div id="share" class="share-component social-share" data-sites="weibo,qzone,qq,wechat"> </div> </div> <div class="act"> <a href="JavaScript:" onclick="zan('139150199391155965')" class="zan" title="赞"> <i class="iconfont bx bx-like"></i> <span id="zan">0</span> </a> </div> </div> <div class="clear"></div> </div> <div class="ny-ad"> </div> <div class="ny-ad"> </div> <div class="like"> <h3 class="title">最新文章</h3> <div class="piclist likep"> <div class="li"> <div class="img"> <a href="https://w.sf024.com/info/1053127440656025659.html" title="您好,在百度看到您说泉州华侨大学的心理医生赵冰洁老师很厉害,您有她的联系方式吗?"> <img src="https://w.sf024.com/assets/img/default.jpg" alt=""> </a> </div> <a href="https://w.sf024.com/ask/2" class="cat">教育 </a> <h3> <a href="https://w.sf024.com/info/1053127440656025659.html" title="您好,在百度看到您说泉州华侨大学的心理医生赵冰洁老师很厉害,您有她的联系方式吗?">您好,在百度看到您说泉州华侨大学的心理医生赵冰洁老师很厉害,您有她的联系方式吗?</a> </h3> <div class="meta"> <span class="time"> <i class="iconfont bx bx-time"></i> 04-15 </span> <span class="views"> <i class="iconfont bx bx-show"></i> 197阅读 </span> </div> </div> <div class="li"> <div class="img"> <a href="https://w.sf024.com/info/2076495649652543908.html" title="报考浙大的研究生需要什么条件"> <img src="https://w.sf024.com/assets/img/default.jpg" alt=""> </a> </div> <a href="https://w.sf024.com/ask/2" class="cat">教育 </a> <h3> <a href="https://w.sf024.com/info/2076495649652543908.html" title="报考浙大的研究生需要什么条件">报考浙大的研究生需要什么条件</a> </h3> <div class="meta"> <span class="time"> <i class="iconfont bx bx-time"></i> 04-15 </span> <span class="views"> <i class="iconfont bx bx-show"></i> 238阅读 </span> </div> </div> <div class="li"> <div class="img"> <a href="https://w.sf024.com/info/397952023654509085.html" title="西安理工大学机械与精密仪器工程学院考研保护第一志愿么"> <img src="https://w.sf024.com/assets/img/default.jpg" alt=""> </a> </div> <a href="https://w.sf024.com/ask/2" class="cat">教育 </a> <h3> <a href="https://w.sf024.com/info/397952023654509085.html" title="西安理工大学机械与精密仪器工程学院考研保护第一志愿么">西安理工大学机械与精密仪器工程学院考研保护第一志愿么</a> </h3> <div class="meta"> <span class="time"> <i class="iconfont bx bx-time"></i> 04-15 </span> <span class="views"> <i class="iconfont bx bx-show"></i> 446阅读 </span> </div> </div> <div class="clear"></div> </div> </div> <div class="ny-ad"> </div> </div> <div class="sidebar"> <div class="widget postlist"> <h3>猜你喜欢</h3> <ul class="hasimg"> <li> <a href="https://w.sf024.com/info/139150199391155965.html" title="JS数组去重: 已知数组 var array=[1,1,2,3,4,6,6,7,8,8,9],如" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="JS数组去重: 已知数组 var array=[1,1,2,3,4,6,6,7,8,8,9],如"> </a> <a href="https://w.sf024.com/info/139150199391155965.html" target="">JS数组去重: 已知数组 var...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 10-29 </span><span> <i class="iconfont bx bx-show"></i> 64阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/525832545347304205.html" title="JS数组去重" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="JS数组去重"> </a> <a href="https://w.sf024.com/info/525832545347304205.html" target="">JS数组去重...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 04-02 </span><span> <i class="iconfont bx bx-show"></i> 90阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/494589409822646532.html" title="JS定义一个函数,可以通过下标删除数组数据,返回新数组,并实现去重,此题如何破" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="JS定义一个函数,可以通过下标删除数组数据,返回新数组,并实现去重,此题如何破"> </a> <a href="https://w.sf024.com/info/494589409822646532.html" target="">JS定义一个函数,可以通过下标删...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 04-14 </span><span> <i class="iconfont bx bx-show"></i> 239阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/392117210847729685.html" title="PHP var_dump可以输出数组中的中文,而用echo将数组中的中文字符串单独输出时是空白。请问怎么解决" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="PHP var_dump可以输出数组中的中文,而用echo将数组中的中文字符串单独输出时是空白。请问怎么解决"> </a> <a href="https://w.sf024.com/info/392117210847729685.html" target="">PHP var_dump可以输出...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 08-14 </span><span> <i class="iconfont bx bx-show"></i> 75阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/717055934774544805.html" title="js数组哪些方法返回" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="js数组哪些方法返回"> </a> <a href="https://w.sf024.com/info/717055934774544805.html" target="">js数组哪些方法返回...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 04-19 </span><span> <i class="iconfont bx bx-show"></i> 111阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/558905387010281772.html" title="js随机数组问题" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="js随机数组问题"> </a> <a href="https://w.sf024.com/info/558905387010281772.html" target="">js随机数组问题...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 04-06 </span><span> <i class="iconfont bx bx-show"></i> 77阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/711267270741264845.html" title="js中数组排序的方法" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="js中数组排序的方法"> </a> <a href="https://w.sf024.com/info/711267270741264845.html" target="">js中数组排序的方法...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 05-24 </span><span> <i class="iconfont bx bx-show"></i> 94阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/1766997838806312900.html" title="已知一个无序数组a[ n ],试编写一算法,实现数组的升序排列。" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="已知一个无序数组a[ n ],试编写一算法,实现数组的升序排列。"> </a> <a href="https://w.sf024.com/info/1766997838806312900.html" target="">已知一个无序数组a[ n ],试...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 09-25 </span><span> <i class="iconfont bx bx-show"></i> 106阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/435292613200594684.html" title="⒐已知一个班有36个学生.用n数组存放学号,a数组存放物理 成绩,b数组存放数学成绩" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="⒐已知一个班有36个学生.用n数组存放学号,a数组存放物理 成绩,b数组存放数学成绩"> </a> <a href="https://w.sf024.com/info/435292613200594684.html" target="">⒐已知一个班有36个学生.用n数...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 08-19 </span><span> <i class="iconfont bx bx-show"></i> 63阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/2117746383212965507.html" title="js如何获取表单中数组的值?" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="js如何获取表单中数组的值?"> </a> <a href="https://w.sf024.com/info/2117746383212965507.html" target="">js如何获取表单中数组的值?...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 05-03 </span><span> <i class="iconfont bx bx-show"></i> 96阅读 </span> </p> </li> </ul> </div> </div> </div> </section><footer class="footer"> <div class="container"> <p class="copyright">COPYRIGHT 2013 - 2024 你问我答网®. ALL RIGHTS RESERVED. | <a href="https://beian.miit.gov.cn/" target="_blank">豫ICP备2020035127号</a></p> </div></footer><script> let search_type="1"; var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?752ceaa2e03e39366ceff9a414a1f6a7"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();</script> <script type="text/javascript" src="https://w.sf024.com/assets/js/jquery.share.min.js"></script> </body> </html>