1

Here is my code :

let x = new Array();
x.push(2);
x.push({'Drake': 12, age: 5})
x.push([1, 7, 4, 12, 19]);

console.log(typeof x);
console.log(x);

console.log(x.includes({'Drake': 12, age: 5}));
console.log(x.includes(2));
console.log(x.includes( [1, 7, 4, 12, 19] ));

The output of the middle console statement is true, but they other two are false. How do I correctly check if another object or an array is included in another array in Javascript ? Any help is appreciated, need to hone my objects skills in Javascript.

APFirebolt
  • 53
  • 1
  • 7
  • 1
    In javascript, `[1,2,3]` and another `[1,2,3]` are two different objects. Sad, but true. – georg Jun 23 '19 at 18:44
  • Not really sad, but decidedly true. If `a === b` then `a` and `b` are interchangeable in JavaScript. Two different arrays aren’t interchangeable (e.g. if you push to one it won’t affect the other). – Ry- Jun 23 '19 at 18:48

0 Answers0