DEV Community

Cristian Fernando
Cristian Fernando

Posted on • Edited on

1

Paracetamol.js💊| #212: Explica este código JavaScript

Explica este código JavaScript

Dificultad: Intermedio

const numbers = [1, 2, 3, 4, 5];
console.log(numbers.with(2, 6)); 🤔
Enter fullscreen mode Exit fullscreen mode
  • A. [ 1, 2, 6, 4, 5 ]
  • B. [ 1, 2, 3, 4, 5 ]
  • C. Array.prototype.whit is not a function
  • D. undefined

Top comments (1)

Collapse
 
duxtech profile image
Cristian Fernando

Respuesta:

  • A. [ 1, 2, 6, 4, 5 ]

with es un nuevo método de arreglos que nos permite reemplazar un elemento por otro.

En el ejemplo: numbers.with(2, 6), el primer parámetro es el index del arreglo al que apuntamos y el segundo parámetro es el elemento en sí que queremos remplazar en la posición especificada.

Esto explica por que cambiamos el elemento 3 por el 6.

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay