Reputation: 279
In my Javascript file, I get datas from server with an Ajax call :
this.$http.get("/data?startDate="+this.filtres.startDate+" "+this.filtres.startHour+"&endDate="+this.filtres.endDate+" "+this.filtres.endHour).then(function(response) {
this.todos = response.body;
this.$forceUpdate();
});
response.body looks like this :
(1) [...]
0: Object { nbPieces: Getter & Setter, TRE: Getter & Setter, TRS: Getter & Setter, ... }
__ob__: {…}
dep: Object { id: 35, subs: [] }
value: Array [ {…} ]
vmCount: 0
<prototype>: Object { walk: walk(), observeArray: observeArray(), … }
length: 1
Now I would like to put value of nbPieces, TRE and TRS into variables. I tried by doing response.body.values()
but I doesn't work.
Upvotes: 0
Views: 102
Reputation: 8515
Your response.body
is an array with an object. If it's always going to have length of 1 then this will work for you:
const [{ nbPieces, TRE, TRS }] = response.body;
and then you can use it like normal variables:
console.log(nbPieces, TRE, TRS);
Upvotes: 1