Los arrays son una estructura de datos simple que se usa en todas partes de la programación. Hay muchas formas de interactuar con arrays en JavaScript.
Hoy, explorarán los arrays y se enseñarán a sí mismos diferentes métodos para manipularlos.
Para cada una de estas tareas, escriban su código directamente en el archivo de la tarea. ¡Los scripts de calificación evaluarán lo que hayan escrito!
-
Usen el método
arr.push()para llenar un array vacío con los números del 1 al 20, en orden. -
Usen el método
arr.reverse()para invertir el orden del array dado. -
Usen el método
arr.splice()para insertar el número faltante en el array dado, en la posición correcta. -
Usen el método
arr.splice()para eliminar uno de los dos números duplicados en el array dado.
¡Si han completado las tareas anteriores, intenten las siguientes tareas extra como desafío adicional!
-
Usen
join()en el array dado para imprimir una cadena de números separados por comas solamente, ¡sin espacios! -
Usen
concat()para fusionar los dos arrays dados, arr1 y arr2, en orden, y luego impriman el nuevo array creado. -
Una matriz es un array de arrays, que representa una cuadrícula con filas y columnas. ¡Usen esta tarea para experimentar con matrices!
- ¿Pueden agregar un solo número a una fila existente?
- ¿Pueden agregar una fila completa de números?
- ¿Pueden eliminar un solo número de una sola fila?
- ¿Pueden invertir una de las filas sin afectar a las demás?
Arrays are a simple data structure used everywhere in programming. There are many ways to interact with arrays in JavaScript.
Today, you will be exploring arrays, and teaching yourselves different methods for manipulating them.
For each of these tasks, type your code directly in the task file - the marking scripts will evaluate what you have written!
-
Use the
arr.push()method to populate an empty array with the numbers 1 to 20, in order. -
Use the
arr.reverse()method to reverse the order of the given array. -
Use the
arr.splice()method to insert the missing number in the given array at the correct position. -
Use the
arr.splice()method to delete one of the two duplicate numbers in the given array.
If you have completed the above tasks, try the following extra tasks for a bonus challenge!
-
Use
join()on the given array to print a string of numbers from it, separated by commas only - no spaces! -
Use
concat()to merge the two given arrays, arr1 and arr2, in order, and then print the new array that's created. -
A matrix is an array of arrays, representing a grid with rows and columns. Use this task to experiment with matrices!
- Can you add a single number to an existing row?
- Can you add a whole new row of numbers?
- Can you remove a single number from a single row?
- Can you reverse one of the rows without affecting the others