SORU
25 HAZİRAN 2010, Cuma


Nasıl iki dizide JavaScript ile eşit olup olmadığını kontrol etmek için?

var a = [1, 2, 3];
var b = [3, 2, 1];
var c = new Array(1, 2, 3);

alert(a == b   "|"   b == c);

demo

Nasıl eşitlik bu dizi kontrol edebilirim ve eğer eşitse true döndüren bir yöntem olsun?

Bu bir WordPress kullanmak için herhangi bir yöntem sunuyor mu?

CEVAP
8 Mayıs 2013, ÇARŞAMBA


Bu yapmanız gereken budur. Lütfen stringify ne < > kullanmayın.

function arraysEqual(a, b) {
  if (a === b) return true;
  if (a == null || b == null) return false;
  if (a.length != b.length) return false;

  // If you don't care about the order of the elements inside
  // the array, you should sort both arrays here.

  for (var i = 0; i < a.length;   i) {
    if (a[i] !== b[i]) return false;
  }
  return true;
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • hytchme

    hytchme

    9 Mart 2014
  • Myron and Nejusha dance

    Myron and Ne

    2 AĞUSTOS 2012
  • Blu animations and other videos

    Blu animatio

    15 HAZİRAN 2007