could you please tell me how to convert an array which is
["apple","banana", "mango"]
to
[{fruit:"apple"},{fruit:"banana"},{fruit:"mango}]
with the parenthesis
something similar to this but with parenthesis JavaScript Add key to each value in array
could you please tell me how to convert an array which is
["apple","banana", "mango"]
to
[{fruit:"apple"},{fruit:"banana"},{fruit:"mango}]
with the parenthesis
something similar to this but with parenthesis JavaScript Add key to each value in array
You're still looking for the .map() function, just like that other question. The only difference is that you want to return an object from the callback, not just a string.
For example:
let input = ["apple","banana", "mango"];
console.log(input.map(x => ({fruit: x})));
As an aside, {} are not parentheses, they are curly braces.