201506022038_《JavaScript权威指南-判断两个数组相等》(p38-48)

var arr1 = [1, 2, 3, 4, 5];

var arr2 = [1, 2, 3, 4, 5];

function equalArrays(a, b) {

  if (a.length != b.length) {

    alert("错啦,数组长度不相等!"

  );

  return

} else {

  for (var i = 0; i < a.length; i++) {

  if (a[i] != b[i]) {

alert("值不相等!");

  return

  }

}

alert("两数组相等!");

return

}

};

equalArrays(arr1, arr2);

posted @ 2015-06-02 21:14  Coca-code  阅读(133)  评论(0编辑  收藏  举报