-2

How to convert array to array object,like

['in','gs'] to [{"state":"in"},{"state":"gs"}]

  • 3
    You could use `Array.map` like so `array.map(v => ({ state: v}))` – Shaegi Apr 29 '21 at 06:24
  • This question doesn't include an attempt to solve the problem. Please read https://idownvotedbecau.se/noattempt and https://idownvotedbecau.se/noresearch – FZs Apr 29 '21 at 08:18

1 Answers1

4

map over it and return a new array

let arr = ['in','gs'] 
let newArr = arr.map(item => ({state: item}));   
console.log(newArr);
Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400