References for other JavaScript array methods
JavaScript arrays are remarkably interesting because they are powerful and have more capabilities available than primitive arrays in other languages. This means that we do not need to write basic capabilities ourselves, and we can take advantage of these powerful features.
We have already covered many different methods within this chapter. Let's look at other useful methods.
Using the isArray method
In JavaScript, we can check the type of a variable or object using the typeof
operator as follows:
console.log(typeof 'Learning Data Structures'); // string
console.log(typeof 123); // number
console.log(typeof { id: 1 }); // object
console.log(typeof [1, 2, 3]); // object
Note that both the object { id: 1}
and the array [1, 2, 3]
have types as object
.
But what if we would like to double check the type is array so we can evoke any specific array method? Thankfully, JavaScript also provides a method for that through Array.isArray...