-1

I have to arrays in javascript. Equality comparison on the elements with both === and == succeeds. But when I do a deep equals on the arrays with chai, I keep getting failure.

What am I doing wrong? Why is one array showing the element as a string. Clearly it's not actually a string, right? Otherwise the === operator would fail.

The type of the elements in the arrays is mongoose ObjectId.

The arrays:

A: ["57af9c0623a2c3b106efa7a8"]
B: [ 57af9c0623a2c3b106efa7a8 ]

A[0] === B[0] // true

The line which fails:

expect(A).to.eql(B);
jenny
  • 13
  • 6

1 Answers1

0

This is two equals array but different objects.

var a = ['57af'];
var b = ['57af'];
console.log(a[0] === b[0], a === b);
---
true, false

Use to compare (from here)

isEqual = a.length == b.length && a.every(function(v,i) { return v === b[i]})
Community
  • 1
  • 1
Aikon Mogwai
  • 4,954
  • 2
  • 18
  • 31