배열 중복 json 의 계승 과 재 구성 제거

55817 단어 javascript 기초
       arr,             tmp ,       arr         tmp ,      ,         

예 를 들 어 var student = ['qiang', 'ming', 'tao', 'li', 'liang', 'you', 'qiang', 'tao'];
첫 번 째 사 고 는 삭제 할 배열 arr 를 옮 겨 다 니 며 요 소 를 각각 다른 배열 tmp 에 넣 고 이 요소 가 arr 에 존재 하지 않 는 다 고 판단 해 야 tmp 에 넣 을 수 있 습 니 다.
두 함수 사용: for... in 과 index Of ()
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">"text/javascript"</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">></code> </div> <div class="line number2 index1 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">var</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">student = [</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'qiang'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">,</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'ming'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">,</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'tao'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">,</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'li'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">,</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'liang'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">,</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'you'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">,</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'qiang'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">,</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'tao'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">];</code> </div> <div class="line number3 index2 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">function</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">unique(arr){</code> </div> <div class="line number4 index3 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js comments" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:rgb(0,130,0) !important;">// arr, tmp ( )</code> </div> <div class="line number5 index4 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">var</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">tmp = </code> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">new</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">Array();</code> </div> <div class="line number6 index5 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">for</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">(</code> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">var</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">i</code> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">in</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">arr){</code> </div> <div class="line number7 index6 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js comments" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:rgb(0,130,0) !important;">// tmp </code> </div> <div class="line number8 index7 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">if</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">(tmp.indexOf(arr[i])==-1){</code> </div> <div class="line number9 index8 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">tmp.push(arr[i]);</code> </div> <div class="line number10 index9 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">}</code> </div> <div class="line number11 index10 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">}</code> </div> <div class="line number12 index11 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">return</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">tmp;</code> </div> <div class="line number13 index12 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">}</code> </div> <div class="line number14 index13 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;">   </div> <div class="line number15 index14 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">
두 번 째 사 고 는 대상 배열 arr 의 요소 값 과 키 의 위 치 를 바 꾸 면 자동 으로 중복 되 는 요 소 를 삭제 합 니 다. 바 꾼 후의 모습: array ('qiang' = > 1, 'ming' = > 1, 'tao' = > 1)
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">"text/javascript"</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">></code> </div> <div class="line number2 index1 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">var</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">student = [</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'qiang'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">,</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'ming'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">,</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'tao'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">,</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'li'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">,</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'liang'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">,</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'you'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">,</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'qiang'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">,</code> <code class="js string" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:#0000FF !important;">'tao'</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">];</code> </div> <div class="line number3 index2 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">function</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">unique(arr){</code> </div> <div class="line number4 index3 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">var</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">tmp = </code> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">new</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">Array();</code> </div> <div class="line number5 index4 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;">   </div> <div class="line number6 index5 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">for</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">(</code> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">var</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">m</code> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">in</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">arr){</code> </div> <div class="line number7 index6 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">tmp[arr[m]]=1;</code> </div> <div class="line number8 index7 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">}</code> </div> <div class="line number9 index8 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js comments" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;color:rgb(0,130,0) !important;">// </code> </div> <div class="line number10 index9 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">var</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">tmparr = </code> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">new</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">Array();</code> </div> <div class="line number11 index10 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;">   </div> <div class="line number12 index11 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">for</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">(</code> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">var</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">n</code> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">in</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">tmp){</code> </div> <div class="line number13 index12 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">tmparr.push(n);</code> </div> <div class="line number14 index13 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">}</code> </div> <div class="line number15 index14 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js keyword" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;min-height: !important;color:rgb(0,102,153) !important;">return</code> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">tmparr;</code> </div> <div class="line number16 index15 alt1" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;">}</code> </div> <div class="line number17 index16 alt2" style="line-height:15.3999996185303px;border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height: !important;"> <code class="js plain" style="border-left-width:3px;border-left-style:solid;border-left-color:rgb(108,226,108);line-height:20px;width:640px;clear:both;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;overflow:visible !important;vertical-align:baseline !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;min-height: !important;"> :http://www.jb51.net/article/54176.htm
세 번 째: ES6 의 새로운 기능:
function unique (arr) {
  const seen = new Map()
  return arr.filter((a) => !seen.has(a) && seen.set(a, 1))
}
// or
function unique (arr) {
  return Array.from(new Set(arr))
}

  :   
  :https://www.zhihu.com/question/29558082/answer/44854426
  :  
        。             ,          。

제 이 슨 계승 과 재 활용
    <br>     function d(opts) {<br>     <span></span>var that = this;<br>         opts = opts || {};<br><br><br>         that.defaults = {<br>             width: null,<br>             height: null,<br>             fieldName: 'file',<br>             quality: 0.7<br>         };<br>         for (var p in opts) {<br>           if (!opts.hasOwnProperty(p)) continue;<br>             that.defaults[p] = opts[p];<br>         }<br>         console.log(that.defaults)<br>     }</span></p>
& lt; p & gt; & lt; span style = "font - size: 14px;" & lt; / 호출 -------------------------- & lt; & lt; / p & gt;
<p><span style="font-size:14px;">  d({<br>     <span></span>  width: "300px",<br>             height: "200px",<br>     })<br>

좋은 웹페이지 즐겨찾기