Guía de Métodos de Arrays en JavaScript: Antiguo vs Nuevo (Con Ejemplos 2025)

Guía práctica de métodos de arrays en JavaScript: ES5 y ES6+, enfoque antiguo y moderno, uso inmutables y ejemplos claros. Ideal para desarrollo a medida con Q2BSTUDIO.

11 sept 2025 • 4 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Introducción: Los arrays son una de las estructuras de datos más importantes en JavaScript. Tanto si trabajas con sintaxis antigua ES5 como con ES6+ y versiones más recientes, dominar las operaciones con arrays es clave para escribir código limpio, eficiente y sin errores. En esta guía práctica repasamos todos los métodos esenciales de arrays en JavaScript con ejemplos del enfoque antiguo y el moderno, además de consejos de uso.

Sobre Q2BSTUDIO: Somos Q2BSTUDIO, empresa de desarrollo de software y aplicaciones a medida, especialistas en inteligencia artificial, ciberseguridad y servicios cloud. Ofrecemos soluciones de software a medida y consultoría en servicios cloud aws y azure, así como servicios de inteligencia de negocio y power bi. Descubre más sobre nuestras soluciones de aplicaciones a medida y sobre nuestros proyectos de inteligencia artificial para empresas.

Operaciones básicas

1 push Añadir al final. Antiguo arr.push(10) Moderno arr = [...arr, 10]

2 pop Eliminar del final. Antiguo arr.pop() Moderno extraer con destructuring [...rest, last] = arr

3 shift Eliminar del inicio. Antiguo arr.shift() Moderno [first, ...rest] = arr

4 unshift Añadir al inicio. Antiguo arr.unshift(5) Moderno arr = [5, ...arr]

Búsqueda y comprobaciones

5 indexOf Índice de la primera aparición. Antiguo arr.indexOf(3) Moderno arr.findIndex(x => x === 3)

6 lastIndexOf Último índice. Antiguo arr.lastIndexOf(3) Moderno arr.findLastIndex(x => x === 3)

7 includes Comprobar existencia. Antiguo arr.indexOf(3) !== -1 Moderno arr.includes(3)

8 at Acceso con índices negativos. Antiguo arr[arr.length - 1] Moderno arr.at(-1)

Iteración y transformación

9 forEach Iterar sin crear array nuevo. Antiguo bucle for Moderno arr.forEach(item => console.log(item))

10 map Transformar cada elemento. Antiguo bucle for con push Moderno arr.map(x => x * 2)

11 filter Filtrar elementos. Antiguo filtro manual Moderno arr.filter(x => x % 2 === 0)

12 reduce Acumular valores. Antiguo bucle sumando Moderno arr.reduce((a, b) => a + b, 0)

13 reduceRight Acumular de derecha a izquierda. Antiguo invertir y reducir Moderno arr.reduceRight((a, b) => a - b)

Añadir, eliminar y copiar

14 splice Insertar o eliminar en índice. Antiguo arr.splice(2, 1, new) Moderno arr = [...arr.slice(0, 2), new, ...arr.slice(3)]

15 slice Copiar parte del array. Antiguo arr.slice(1, 3) Moderno [...arr].slice(1, 3)

16 concat Unir arrays. Antiguo arr.concat(arr2) Moderno [...arr, ...arr2]

17 flat Aplanar arrays anidados. Antiguo arr.reduce((a, b) => a.concat(b), []) Moderno arr.flat()

18 flatMap Mapear y aplanar en un paso. Antiguo arr.map(fn).flat() Moderno arr.flatMap(fn)

Ordenación y reverso

19 sort Ordenar. Antiguo arr.sort() Moderno arr.toSorted() devuelve copia ordenada sin mutar

20 reverse Invertir orden. Antiguo arr.reverse() Moderno arr.toReversed()

Métodos utilitarios

21 join Convertir a cadena. Antiguo arr.join(,) Moderno [...arr].join( - )

22 toString Representación en cadena. Antiguo arr.toString() Moderno String(arr)

23 from Crear array desde iterable. Antiguo [].slice.call('hello') Moderno Array.from('hello')

24 isArray Comprobar si es array. Antiguo obj instanceof Array Moderno Array.isArray(obj)

25 keys values entries Iteradores. Moderno for (let [i, v] of arr.entries()) console.log(i, v)

Métodos inmutables recientes ES2023+

toSorted para ordenar sin mutar, toReversed para invertir sin mutar y with(index, value) para crear copias con reemplazo. Estas alternativas reducen errores en aplicaciones complejas y mejoran la seguridad funcional del código.

Ejemplos rápidos de uso moderno

Duplicar valores let doubled = arr.map(x => x * 2) Filtrar pares let evens = arr.filter(x => x % 2 === 0) Sumar elementos let total = arr.reduce((a, b) => a + b, 0)

Preguntas frecuentes resumidas

Cuáles son los métodos más comunes push pop shift unshift map filter reduce slice splice concat includes

Cuál es la diferencia entre sintaxis antigua y nueva La antigua depende de bucles y métodos que mutan el array. La moderna usa spread map filter reduce y métodos inmutables como toSorted toReversed with para código más declarativo y seguro

Cómo comprobar si un valor es array Usar Array.isArray(value) en lugar de instanceof

Por qué preferir sintaxis moderna Código más limpio, enfoque funcional, menos efectos secundarios y mejor mantenimiento en proyectos grandes

Conclusión y servicios Q2BSTUDIO: Dominar los métodos de arrays es esencial para cualquier desarrollador JavaScript en 2025. En Q2BSTUDIO combinamos conocimiento técnico en desarrollo de software a medida, inteligencia artificial, agentes IA, ciberseguridad, servicios cloud aws y azure, y servicios de inteligencia de negocio como power bi para ofrecer soluciones completas a empresas. Si necesitas crear aplicaciones a medida, optimizar procesos con automatización o integrar IA para empresas, podemos ayudarte a diseñar e implementar la solución adecuada.

Palabras clave integradas: 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.

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.