A
A
AntonVirovets2018-03-22 21:46:19
JavaScript
AntonVirovets, 2018-03-22 21:46:19

How to find out if an array element is equal to an object?

Hello everyone) There is such a task: There are 2 arrays, you need to compare them by value and if they are equal, return true, and if they are not equal, return false.
There are several questions. it turns out there are just strings, there are objects, there is another array. I need to check what type the element is, and if, for example, element = object, then for in, and if element = array, then just for. How to do it? How to write this code (if(element == object){...}), and the same with an array? Here is such an array.
var array1 = [
null,
"Marvel",
"2.0.17",
{
name: "Hulk",
color: "green",
age: 31,
abilities: ["crash", "smash"]
},
name: "Iron Man",
age: 35,
stillAlive: true
},
["Captain America", "Thor", "Captain Marvel"]
];

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-03-22
@AntonVirovets

if (elem instanceof Array) {
  ...
} else if (elem instanceof Object) {
  ...
} else ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question