Javascript JSON stringify No Numeric Index to include in Data

前端 未结 8 1348
天涯浪人
天涯浪人 2021-01-28 10:52

i am trying to pass non numeric index values through JSON but am not getting the data.

var ConditionArray = new Array();
ConditionArray[0] = \"1\";
ConditionArra         


        
8条回答
  •  被撕碎了的回忆
    2021-01-28 11:20

    Since javascript array accepts numeric index only. If you want non numeric index,use Object instead.

    var ConditionArray = {};
    ConditionArray[0] = "1";
    ConditionArray[1] = "2";
    ConditionArray[2] = "3";
    
    ConditionArray['module'] = "Test";
    ConditionArray['table']  = "tab_test";
    var Data = JSON.stringify(ConditionArray);
    

    Here is the working DEMO : http://jsfiddle.net/cUhha/

提交回复
热议问题