0

Lets say I have an array object like this:

var a = {
    data: [
      'name': 'somename',
    ]

}

Here I want to check if my array has list. If it is then I want convert the list into json and return new value.

I can do this in python like:

assets = {}
            for k,v in data.items():
                if type(v) is list:
                    assets[k] = json.dumps(v)
                else:
                    assets[k] = v

How can I achieve this in javascript ??

gamer
  • 5,673
  • 13
  • 58
  • 91

1 Answers1

0

There is not list type in javascript.

The type Array is the one closer to your question.

To check if a variable v is an Array you can do the following:

if (v instanceof Array) {
   // Do something if v is an array
}
Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56