Domina Spread y Rest de Objetos en JavaScript

Guía práctica de spread y rest para objetos en JavaScript: fusiona, sobrescribe y desestructura con ejemplos, consejos y buenas prácticas para código inmutable.

7 sept 2025 • 2 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Hola devs Hoy vamos a dominar los operadores de objetos en JavaScript: Spread ... y Rest ... Dos características potentes que a veces confunden a quienes empiezan. Aquí tienes una guía clara, ejemplos simples y una conclusión práctica.

Spread de objetos Spread sirve para copiar superficialmente, fusionar y sobrescribir propiedades en objetos. El orden importa: si repites una clave, la última gana. Ojo, es copia superficial, las referencias anidadas se comparten.

Ejemplo 1 Fusionar objetos const detalles = { id: 1, colorId: 10 }; const habitat = { regionId: 5, climaCalido: true }; const ave = { ...detalles, ...habitat }; Resultado ave = { id: 1, colorId: 10, regionId: 5, climaCalido: true }

Ejemplo 2 Sobrescribir propiedades const coche = { brandId: 100, modelId: 200, colorId: 1 }; const nuevoCoche = { ...coche, speedKmh: 220, brandId: 300, modelId: 400 }; Resultado nuevoCoche = { brandId: 300, modelId: 400, colorId: 1, speedKmh: 220 }

Rest de objetos Rest te permite extraer propiedades específicas y agrupar el resto en un nuevo objeto durante la desestructuración.

Ejemplo 1 Desestructuración directa const usuario = { id: 15, age: 22, score: 45, cityId: 7 }; const { id, age, ...otros } = usuario; Ahora id y age quedan fuera, y otros es { score: 45, cityId: 7 }

Ejemplo 2 Dentro de una función function resumen({ id, age, ...otros }) { console log de otros y de id y age } resumen(usuario)

Consejos rápidos Usa spread para crear nuevos objetos sin mutar el original. Recuerda que el último spread o la última clave sobrescribe valores previos. Para estructuras profundamente anidadas considera técnicas de copia profunda o utilidades específicas. Rest te ayuda a quedarte con lo que importa y agrupar el resto de forma limpia.

Resumen Spread ... copiar, fusionar y sobrescribir propiedades. Rest ... recolectar propiedades restantes tras extraer algunas claves.

Cómo lo aplicamos en Q2BSTUDIO En Q2BSTUDIO diseñamos aplicaciones a medida y software a medida con buenas prácticas modernas de JavaScript y TypeScript, aprovechando patrones inmutables con spread y rest para mejorar mantenibilidad y rendimiento. Si buscas un partner para crear productos digitales escalables, descubre nuestro enfoque de desarrollo de aplicaciones y software multiplataforma a medida. También impulsamos soluciones de inteligencia artificial, ia para empresas y agentes IA integrados en tus procesos, como parte de nuestras capacidades de inteligencia artificial aplicada.

Más servicios que potenciamos ciberseguridad y pentesting, servicios cloud aws y azure, servicios inteligencia de negocio y power bi, automatización y orquestación de procesos, integración de datos y arquitecturas event driven. Nuestro objetivo es acelerar la entrega de valor con calidad técnica y foco en negocio.

Palabras clave aplicaciones a medida, software a medida, inteligencia artificial, ciberseguridad, servicios cloud aws y azure, servicios inteligencia de negocio, ia para empresas, agentes IA, power bi.

Tu turno Cuál es tu caso favorito para usar spread o rest en objetos JS Compártelo y si quieres que revisemos tu código o arquitectura, hablamos.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat