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?
You can use map
var res = [{"meta_value":"Germany"},{"meta_value":"United States"}].map(function (el) {
return el.meta_value;
})
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.