Reputation: 325
Hello I have a function and I would like to make variables from returned array, is it possible?
var food,car=getItems();
function getItems(){
var array=["pizza","audi"];
return array;
}
Upvotes: 0
Views: 67
Reputation: 207901
Just wrap your variables in []
to use destructuring assignment (no jQuery needed):
var [food,car]=getItems();
var [food,car]=getItems();
function getItems(){
var array=["pizza","audi"];
return array;
}
console.log(food,car)
Upvotes: 1