-2

How to convert array to array object,like

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

2
  • 3
    You could use Array.map like so array.map(v => ({ state: v})) Commented Apr 29, 2021 at 6:24
  • This question doesn't include an attempt to solve the problem. Please read idownvotedbecau.se/noattempt and idownvotedbecau.se/noresearch Commented Apr 29, 2021 at 8:18

1 Answer 1

4

map over it and return a new array

let arr = ['in','gs'] 
let newArr = arr.map(item => ({state: item}));   
console.log(newArr);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.