0

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?

2 Answers 2

2

You can use map

var res = [{"meta_value":"Germany"},{"meta_value":"United States"}].map(function (el) {
   return el.meta_value;
})
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.