0

Im seeing a lot of answers to this in simple arrays but I need the keys and value. I have a json object but need an array. The object looks like this:

{"Food":"Starbucks", "Job":"Electrician"}

I just need a simple array like this:

["Food" => "Starbucks", "Job" => "Electrician"]

Edit: Im not sure how to type it out. Just need to be able to do an array.map and get the keys and values in javascript.

Here is the final code that I am trying:

const details = jsonObject;

{details.map(function(item,idx){
                return<DetailCell>
                    <Label>{idx}</Label>
                    <Text style={TextStyle}>{item}</Text>
                </DetailCell>
             })}

Label should be the key and the Text should be the value.

Tyler Nichol
  • 635
  • 2
  • 7
  • 28

2 Answers2

0

I think you need this :

[{"Food" : "Starbucks"}, {"Job" : "Electrician"}]
Valeriane
  • 936
  • 3
  • 16
  • 37
  • 1
    This can't be really, then you need to `arr[0].Food` to get `Starbucks` out which is way more harder then `obj.Food` – halilcakar Jun 09 '20 at 20:28
-1

To declare a literal array value is something like this in JSON in node.

{JSONVarWithArrayValue : [0,0,0,0]}