MeshWorld India LogoMeshWorld.

How to add an element to ending of an array with ES6

Listen to ArticleAI Speech
~1 min read narration
100%
How to add an element to ending of an array with ES6

The spread operator ..., introduced first in ES6 became one of the most popular and favourite feature among the developers.

A separate RFC was made for this much widely accepted feature to extend its functionalities to objects, prior it only worked on arrays.

This tutorial describes how to add element to the ending of an array using spread operator in ES6

Example with animals emoji

let animals = ["🦁", "🐵", "🐕", "🦊", "🐯"];
console.log(animals);
// Output → ["🦁", "🐵", "🐕", "🦊", "🐯"]

console.log(animals.length);
// Output → 5

animals = [...animals, "🦄"];

console.log(animals.length);
// Output → 6

console.log(animals);
// Output → ["🦁", "🐵", "🐕", "🦊", "🐯", "🦄"]

// now with multiple elements
animals = [...animals, "🐆", "🦓", "🐼", "🦘"];

console.log(animals.length);
// Output → 10

console.log(animals);
// Output → ["🦁", "🐵", "🐕", "🦊", "🐯", "🦄", "🐆", "🦓", "🐼", "🦘"]

Happy coding

Reader Quality Feedback

Did this technical guide help solve your problem?

Suggest Errata ($0)
Vishnu
Primary Author

Vishnu

Founder & Principal Architect at MeshWorld. Senior engineer and instructor specializing in AI agent systems, scalable web architecture, and modern development workflows.

Explore Author Archive
Compute Fuel & Open Testbed
100% Independent & Verified

Fuel High-Density, Zero-Fluff Engineering Deep-Dives

Every guide on MeshWorld is validated on physical Linux nodes and reproducible testbeds. If this article saved you hours of debugging or unblocked production, consider funding our next cluster run.

Weekly Dispatch

Join MeshWorld Dispatch

Get practical tutorials, system blueprints, and curated AI engineering notes straight to your inbox. No fluff, zero spam.

Zero spam. 1-click unsubscribe anytime.Prefer RSS?
Curated Continuations

Up Next in This Domain.

Browse Full Archive