In JavaScript, the entire array can be accessed by referencing its name.
Example
const cars = [“Saab”, “Volvo”, “BMW”]; document.getElementById(“demo”).innerHTML = cars; |
Arrays are a unique category of objects. When assessed with the typeof operator in JavaScript, arrays return “object”.
However, it’s more accurate to characterize JavaScript arrays simply as arrays.
Arrays employ numerical indices to retrieve their “elements”. In this instance, person[0] retrieves “John”.
const person = [“John”, “Doe”, 46]; |
Objects utilize names to access their “members”. In this instance, person.firstName retrieves “John”.
const person = {firstName:“John”, lastName:“Doe”, age:46}; |