Suggest an editImprove this articleRefine the answer for “What does push() do?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)The **`push()`** method adds one or more elements to the end of an array and returns the new length of the array. **Key point:** `push()` mutates the original array and returns not the array itself, but the number of elements after adding.Shown above the full answer for quick recall.Answer (EN)ImageThe `push()` method is one of the most frequently used in JavaScript. It **adds one or more elements to the end of an array** and **returns the new length of the array**. --- ## Example: ```javascript const fruits = ["apple", "banana"]; const newLength = fruits.push("cherry"); console.log(fruits); // ["apple", "banana", "cherry"] console.log(newLength); // 3 ``` - The method **modifies the original array (mutates it)**. - It returns not the array itself, but **the number of elements after adding**. --- ## You can add several elements at once: ```javascript const arr = [1, 2]; arr.push(3, 4, 5); console.log(arr); // [1, 2, 3, 4, 5] ``` --- ## Behavior: - Elements are added **to the end of the array**. - The indexes of the new elements start at the current `length`. - The return value is the new value of `arr.length`. --- ## Important: - `push()` only works **with arrays** (or array-like objects). - If you do `arr = arr.push(...)`, you lose the array itself: ```javascript const arr = [1, 2]; arr = arr.push(3); // mistake - arr becomes a number (3) ``` --- ## In short: | What it does | Adds elements to the end of the array | |---|---| | Modifies the original array? | Yes | | Returns | The new length of the array | | Can add several elements | Yes | | Example | `arr.push(1, 2, 3)` | --- ## Alternative (without mutation): If you want to add an element **without changing the original**: ```javascript const arr = [1, 2]; const newArr = [...arr, 3]; console.log(newArr); // [1, 2, 3] console.log(arr); // [1, 2] (unchanged) ```For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.