DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Array Sub

07.02.2009
| 1835 views |
  • submit to reddit
        // description of your code here

  //陣列相減  array1 - array2
  function array_cut(array1, array2){
    var flag;
    var temp_array = [];
    for (var i=0; i < array1.length; i++){
      flag = 0;
      for (var j=0; j < array2.length; j++) {
        //表示有相同的, 所以會被剪掉
        if (array1[i] == array2[j]) {
          flag = 1;
        }
      }
      //如果還是0 表示都沒相同的, 所以會留下來
      if (flag == 0) {
        temp_array.push(array1[i]);
      }
    }
    return temp_array
  }