Introducci贸n a JavaScript
驴Por qu茅 aprender JavaScript?
隆Hola Mundo! en Mac
隆Hola Mundo! en Windows
Anatom铆a de una variable
Tipos de datos en JavaScript
Creaci贸n de strings
Operadores aritm茅ticos
Conversi贸n de tipos: Type Casting y Coerci贸n
Conversi贸n de tipos expl铆cita e impl铆cita
Estructuras de Control y L贸gica
Operadores de comparaci贸n
Operadores l贸gicos
Ejecuci贸n condicional: if
Ejercicio: Adivina el n煤mero
Ejecuci贸n condicional: switch
Loop: for
Loop: for of
Loop: for in
Loop: while
Loop: do while
Funciones y This
Anatom铆a de una funci贸n
Funciones vs M茅todos
Funciones puras e impuras
Arrow function y enlace l茅xico
Contextos de ejecuci贸n y scope chain
驴Qu茅 es Closure?
Preguntas a Desarrolladores Senior: 驴Por qu茅 aprender Desarrollo Web?
Manipulaci贸n de Arrays
Introducci贸n a Arrays
Mutabilidad e inmutabilidad de Arrays
Modificaci贸n b谩sica del final con push( ), pop( )
Iteraci贸n con map( ) y forEach( )
Filtrado y reducci贸n con filter( ) y reduce( )
B煤squeda de elementos con find( ) y findIndex( )
Crear copias con slice( )
Spread operator: casos de uso
Programaci贸n Orientada a Objetos
Anatom铆a de un Objeto
Trabajando con objetos en JavaScript
Funci贸n constructora
驴Qu茅 es una clase?
Prototipos y herencias
Herencia en la pr谩ctica
Prototipos en la pr谩ctica
this en JavaScript
Proyecto: Crea una red social
Proyecto: Crea una red social parte 2
Asincron铆a en JavaScript
驴C贸mo funciona el JavaScript Engine?
Promesas en JavaScript
Usando Async y await en JavaScript
For await of
驴C贸mo funciona la web?
驴C贸mo funciona HTTP?
M茅todo GET en JavaScript
M茅todo POST en JavaScript
M茅todo DELETE en JavaScript
Importancia del id en el m茅todo DELETE
ECMAScript 6 y tus siguientes pasos
You don't have access to this class
Keep learning! Join and start boosting your career
The "for" is one of the most fundamental and powerful structures in JavaScript to perform iterations or loops, allowing you to step through elements within a list or array. You may be wondering, how does it work and why is it so valuable? Here I will explain it in a simple and practical way.
The "for" method in JavaScript is a tool that allows us to repeat the execution of a block of code until a specified condition is false. It consists of three main steps within its parentheses:
let i = 0
.i < list.length.
(i++
).The basic structure is as follows:
for (let i = 0; i < list.length; i++) { // Code to execute}
To make it more practical, let's do an example. Suppose we have an array with several elements that we want to print on the console.
First, we define our array:
let list = ["eat", "sleep", "code", "repeat"];
Then, we implement the "for" loop:
for (let i = 0; i < list.length; i++) { console.log(list[i]);}
list
contains four elements of type string.i = 0
and continues as long as i < list.length
(4 in this case).console.log(list[i]);
prints the current element based on index i
.i++
ensures that the loop advances to the next index of the array.The result when executing this code will be:
eatsleepcoderepeat
Each time the "for" loop executes, it performs the following steps:
i
to move to the next element.let i = 0
, to maintain clarity.console.log
, "for" can be adapted to more complex tasks by transforming or accumulating data.Now it's your turn! Practice is key. Try implementing a "for" loop in simple projects to solidify the use of this powerful structure. And remember, keep exploring and expanding your JavaScript skills; constant learning opens doors to endless possibilities in the programming world.
Contributions 28
Questions 0
Want to see more contributions, questions and answers from the community?