Sube de nivel JavaScript: Métodos de Array (Parte 2)

Guía práctica de JavaScript: Parte 2 de Métodos de Arrays. Domina concat, copyWithin, slice, splice y toSpliced con ejemplos claros y código eficiente.

17 ago 2025 • 3 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Introducción Parte 2 Métodos de Arrays

En la entrega anterior exploramos métodos esenciales de arrays en JavaScript y cómo facilitan el trabajo con datos. En esta segunda parte seguiremos con métodos más potentes para manipular, buscar y transformar arrays con menos código y mayor eficiencia.

1. concat

concat crea un nuevo array combinando dos o más arrays sin modificar los originales.

Ejemplo

const a = [1, 2]; const b = [3, 4]; const result = a.concat(b); console.log(result); // [1, 2, 3, 4]

2. copyWithin()

copyWithin copia un conjunto de elementos dentro del mismo array a otra posición y modifica el array original.

Ejemplo

const arr = [1, 2, 3, 4, 5]; arr.copyWithin(1, 3); console.log(arr); // [1, 4, 5, 4, 5]

3. slice()

slice devuelve una copia superficial de una porcion del array en un nuevo array, desde start hasta end sin incluir end. No modifica el array original.

Ejemplo

let frutas = [apple, banana, mango, orange]; let porcion = frutas.slice(1, 3); console.log(porcion); // [banana, mango]

Explicacion: 1 es el indice de inicio incluye el valor en indice 1 banana. 3 es el indice de fin y excluye el valor en indice 3 por eso el resultado es desde el indice 1 hasta el 2 [banana, mango].

4. splice()

splice añade o elimina elementos desde un indice especificado y modifica el array original.

Ejemplo

let frutas = [apple, banana, mango, orange]; frutas.splice(1, 2, grape, kiwi); console.log(frutas); // [apple, grape, kiwi, orange]

Explicacion: 1 es el indice de inicio donde comienza la eliminacion 2 es el numero de elementos a eliminar aqui banana y mango y grape, kiwi son los elementos que se insertan en esa posicion. splice modifica el array original a diferencia de slice.

5. toSpliced()

toSpliced funciona igual que splice en cuanto a argumentos start deleteCount y elementos a insertar pero en lugar de modificar el array original devuelve un nuevo array con los cambios. Esto es util cuando quieres evitar mutaciones, por ejemplo en programacion funcional o en actualizaciones de estado en React.

Ejemplo

let frutas = [apple, banana, mango, orange]; let nuevas = frutas.toSpliced(1, 2, grape, kiwi); console.log(nuevas); // [apple, grape, kiwi, orange] console.log(frutas); // [apple, banana, mango, orange]

Conclusión

Con estos métodos puedes manipular arrays de forma eficaz y con menos codigo. Practica su uso para que se vuelvan naturales en tu dia a dia como desarrollador.

En Q2BSTUDIO somos una empresa de desarrollo de software y aplicaciones a medida especialistas en inteligencia artificial ciberseguridad y mucho mas. Ofrecemos software a medida y aplicaciones a medida integrando inteligencia artificial y agentes ia para mejorar procesos de negocio. Además contamos con servicios cloud aws y azure, servicios de inteligencia de negocio y soluciones con power bi para visualizacion y analitica. Nuestras capacidades en ia para empresas y agentes ia se combinan con estrategias de ciberseguridad para entregar proyectos robustos y escalables. Si buscas soluciones personalizadas de software a medida o deseas potenciar tus datos con inteligencia artificial y servicios inteligencia de negocio contacta con Q2BSTUDIO para una propuesta adaptada a tus necesidades.

Haz hoy algo que tu futuro yo te agradezca

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