[Vuejs]-How to destructure an Array while assigning the value to a Vue instance data property

4👍

You can do it like this:

const arr = [1, 2, 3];
const post = { media: 0 };

[post.media] = arr;

console.log(post.media);

So in your case

[this.post.media] = data;

But in my opinion there’s nothing wrong with your line of code. It’s totally readable and very clear what you’re trying to achieve.

Leave a comment