1

I have done this basic algoritm, for putting all the data of the object's attributes inside of a array, there is a better way of doing this, I am a beginner on Javascript, thanks for the help.

const datos = {
    nombre:"Kurosaki",
    apellido:"Ichigo",
    edad:20,
    altura:180,
    eresDesarrollador:false,
}

//Con este algoritmo se almacenan sin el uso de metodos los valores del objeto datos en un array
var i = 0
var array = []
for (const valor in datos) {
   
    array[i] = datos[valor] 
    i++;
}
console.log(array)// Output [ 'Kurosaki', 'Ichigo', 20, 180, false ]

I would like to know if exists a method() for improving this code, and make it shorter

Arro3847
  • 21
  • 6

1 Answers1

1

There is the Object.values() method.

I got the answer from a similar post: Javascript equivalent of Python's values() dictionary method. You have to scroll down a bit.

Edit: here's the original answer from the above post. https://stackoverflow.com/a/23780751/21371665 I didn't originally know how to share that specific answer.