Reputation:
I have array with such values:
[{"meta_value":"Germany"},{"meta_value":"United States"}]
I need someway to convert it for list of values for autocomplete: [Germany, United States].
How to do it in the proper way?
Upvotes: 0
Views: 42
Reputation: 29836
Use Array.prototype.map()
to map one array to another array based on a mapping function:
var metaArr = [{"meta_value":"Germany"},{"meta_value":"United States"}];
var arrayOfStates = metaArr.map(function(item){return item.meta_value});
Simply use arrayOfStates
as your source for the autocompletion.
Upvotes: 1
Reputation: 77482
You can use map
var res = [{"meta_value":"Germany"},{"meta_value":"United States"}].map(function (el) {
return el.meta_value;
})
Upvotes: 2