0

I have created an array here is my React Native code

this.state.ratingArray[key_value] = rating;

It is providing this data formate

[
key1: value,
key2: value,
key3: value,
] 

And i want to convert it in

[
{key1 : value},
{key2 : value},
{key3 : value}
]

how can i do that please suggest something. Thanks in advance.

S.Hashmi
  • 485
  • 1
  • 8
  • 29
  • Are you sure about the square brackets in your provided data format? I think those should be curly braces – yunzen Feb 15 '21 at 08:34
  • The first example isn't valid for an array, so it's not clear what you are trying to do or want. Where is this data coming from? What is its real format? – Drew Reese Feb 15 '21 at 08:34
  • In array, you can't have keys. The array automatically initialized by a numeric sequence starting with 0. if you are supposed to convert it must be converted into an object with the key as index and value and the value you initialized. – Jignesh Mayani Feb 15 '21 at 08:35
  • const obj = arrayData.map( data => { return { 'key': data } }); though your array representation syntax is not correct – fxnoob Feb 15 '21 at 08:40

0 Answers0