[Vuejs]-Array.from(Object).forEach not working with vue.js

4👍

Array from creates an array from an iterable, which does not work on plain objects.

The Array.from() static method creates a new, shallow-copied Array instance from an array-like or iterable object.

You could use Object.values, Object.entries or Object.keys

Object.values(this.user).forEach((value) => {
  console.log(value)
});

0👍

The Array.from() cannot create an array from your object. Instead of it, you could just use the old simple way:

for (const key in this.user) {
  console.log(this.user[key]);
}
👤Victor

Leave a comment