[Vuejs]-Reverse JSON data in Vue.JS using reverse()

0👍

You can reverse an array. Take a look at my fiddle. I replaced getJSON with fetch to use promises. Also you don’t need to do var _this = this;
It looks a bit weird. Since in Vue.js properties are reactive you can just set a value.

Here is a code:

const app = new Vue({
  el: '#app',
  data: {   
    items: []
  },
  created: function() {
    fetch('https://api.jsonbin.io/b/5b02b2bbc83f6d4cc7349a7b')
      .then(resp => resp.json())
      .then(items => {        
        this.items = items.reverse()
      })
  }
});

0👍

I think what you want is something like this:

_this.json = json.reverse();

That is, assuming json is an already parsed json array. Otherwise, first parse the json string:

const array = JSON.parse(jsonString);
this.data = array.reverse();

The way you are doing you are trying to assign a value to the result of an expression, which doesn’t make much sense (right side values can’t be assigned to).

Leave a comment