What are array properties?#
Array properties define specific attributes of an array, such as its size or structure. These are usually static values that describe or affect the array’s behavior. For example:
Properties allow you to query or adjust key characteristics of an array without extra effort.
What are array methods?#
Array methods, conversely, are actions or functions that you can apply to an array to manipulate data. For example:
These methods simplify modifying, accessing, and organizing array data dynamically.
Functions are a set of instructions that carry out a task. They allow us to reuse code anywhere in the program.
Why does it matter?
With these tools, you don’t need to create custom objects or write repetitive code. Array methods and properties provide a robust framework for handling data efficiently.
Now, we’ll examine two powerful JavaScript array methods—map()
and reduce()
—and see how they simplify common data operations.
Array map() method#
The map()
method creates a modified version of an array by applying a callback function to each element. It returns a new array containing the results of the function applied to every element in the original array without altering the original array.
The syntax of the method is as follows: