I want to be able to convert an array of values like this : ["apple", "pear", "orange","banana" ] into an array in this format
[
{"value": "apple"},
{"value": "pear"},
{"value": "orange"},
{"value": "banana"}
]
I'd be grateful for any advice.
Use .map :
/*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/
const input = ["apple", "pear", "orange","banana"],
output = input.map(fruit => ({value: fruit}));
console.log(output);
<!-- https://meta.stackoverflow.com/a/375985/ --> <script src="https://gh-canon.github.io/stack-snippet-console/console.min.js"></script>