“cara membandingkan dua array javascript” Kode Jawaban

ES6 Bandingkan dua array

let difference = arrA.filter(x => !arrB.includes(x));
Adventurous Ant

Diff Dua Array JavaScript

function diffArray(arr1, arr2) {
  return arr1
    .concat(arr2)
    .filter(item => !arr1.includes(item) || !arr2.includes(item));
}
Yawning Yacare

JavaScript membandingkan array

Array.prototype.equals = function(arr2) {
  return (
    this.length === arr2.length &&
    this.every((value, index) => value === arr2[index])
  );
};

[1, 2, 3].equals([1, 2, 3]);	// true
[1, 2, 3].equals([3, 6, 4, 2]);	// false
garzj

Cara membandingkan array di JS

// THE PROBLEM:
const firstArray = ["cookies", "milk", "chocolate"]
const secondArray = ["cookies", "milk", "chocolate"]
console.log(firstArray == secondArray) // always returns FALSE

// THE SOLUTION:
if(JSON.stringify(firstArray) === JSON.stringify(secondArray)){
  console.log("firstArray is the same as the secondArray")
} else {
  console.log("firstArray is different from the secondArray")
}
Disgusted Dunlin

JavaScript Bandingkan dua array terlepas dari ketertiban

const isEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);

// Examples
isEqual([1, 2, 3], [1, 2, 3]);      // true
isEqual([1, 2, 3], [1, '2', 3]);    // false
Batman

cara membandingkan dua array javascript

function arraysAreIdentical(arr1, arr2){
    if (arr1.length !== arr2.length) return false;
    for (var i = 0, len = arr1.length; i < len; i++){
        if (arr1[i] !== arr2[i]){
            return false;
        }
    }
    return true; 
}
Spotless Shrew

Jawaban yang mirip dengan “cara membandingkan dua array javascript”

Pertanyaan yang mirip dengan “cara membandingkan dua array javascript”

Lebih banyak jawaban terkait untuk “cara membandingkan dua array javascript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya