There is two ways to figure out if an array is an array or an object. Using typeof item === "object";
will return true for an object and an array since arrays are relatively new to javascript and arrays are prototypes of objects(may have worded this wrong, feel free to correct me). So the two ways I know of to determine if an Array is an Array are:
Solution 1:
Array.isArray(item);
Solution 2:
item instanceof Array;
My questions are:
- What is the difference between these two solutions?
- Which of these two is the preferred solution?
- Which has a faster process time?