如何在JavaScript中区分数组和json对象

时间:2019-08-30 05:57:28

标签: javascript json

“我想区分json对象和javascript中的数组。”
    ****************************************************** ************************       例如:data = {“ 1”:2,                                         “ 2”:[1,32,4],                                         “ 3”:{“ x”:“ y”},                                         “ 4”:[{“ q”:“ w”},{“ a”:“ s”},{“ z”:“ x”}],                                         “ 5”:true}

    data['2'] and data['3'] both are object,

    typeof(data['2']) -- object
    typeof(data['3']) -- object

    Even if i try to iterate over items to check which has key value using for loop.
    for item in data['2']-- return index 012(as string)
    for item in data['3']-- return keys(as string)

0 个答案:

没有答案