Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

219
Vistas
Converting arrays nested in array into object using forEch (does not work somehow?)

I am having trouble with something i thought it will be simple.

I have an array of nested arrays with strings.

const cities = [['Vienna'],['Berlin'],['London'],['Oslo'],['New York']]

I must convert these nested arrays into objects. I think forEach method should suit perfectly along with Object.assign.

I written something like these:

function convert(element) {
    Object.assign({}, element)
  }
  const Test = cities.forEach(convert)

But then i am getting from console.log(Test) undefinded. Why so ? I am iterating through the whole array and each of her arrays should be assign as object. Whats missing ?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Object should contain key: value pair

If you want to convert each string element into an object element. Then you can do something like this :

const cities = [['Vienna'],['Berlin'],['London'],['Oslo'],['New York']]

const res = cities.map((item) => {
    return {
    city: item[0]
  }
});

console.log(res);

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda