Skip to main content
se añadieron 10 caracteres en el cuerpo
Origen Enlace

the declaration of the resultla declaración de la variable must be out of the loopde result debe estar fuera del ciclo

'use strict'

  var array = [];

  var words = ["JHON", "CHARLES","KERLYN","YEAH","JUAN"]

  var result = [];

  words.forEach((element,index)=>{

    if(element.lastIndexOf("J")==0){

      result.push(element);

    }
    console.log(result)
 })

the declaration of the result variable must be out of the loop

'use strict'

  var array = [];

  var words = ["JHON", "CHARLES","KERLYN","YEAH","JUAN"]

  var result = [];

  words.forEach((element,index)=>{

    if(element.lastIndexOf("J")==0){

      result.push(element);

    }
    console.log(result)
 })

la declaración de la variable de result debe estar fuera del ciclo

'use strict'

  var array = [];

  var words = ["JHON", "CHARLES","KERLYN","YEAH","JUAN"]

  var result = [];

  words.forEach((element,index)=>{

    if(element.lastIndexOf("J")==0){

      result.push(element);

    }
    console.log(result)
 })
Origen Enlace

the declaration of the result variable must be out of the loop

'use strict'

  var array = [];

  var words = ["JHON", "CHARLES","KERLYN","YEAH","JUAN"]

  var result = [];

  words.forEach((element,index)=>{

    if(element.lastIndexOf("J")==0){

      result.push(element);

    }
    console.log(result)
 })