jquery make single variables from returned array

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

Answers (1)

j08691
j08691

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

Related Questions