嘗試將一個JavaScript對象分割成一個哈希數組..我必須根據符號「|」的出現來拆分數組內的內容。將一個javascript對象分割爲一個鍵值數組
我輸入數組看起來像
{
"testFieldNames": ["testNumber", "testName", "testDate1", "testDate2"]
},
"data": [
"4|Sam|2012-02-10T00:00Z",
"0|Wallace|1970-01-01T00:00Z|2012-02-10T00:00Z"
]
};
和預期輸出是[{"testNumber" : "4", "testName" : "Sam", "testDate1" : "2012-02-10T00:00Z", "testDate2" : "0"},{"testNumber" : "0", "testName" : "Wallace", "testDate1" : "1970-01-01T00:00Z", "testDate2" : "2012-02-10T00:00Z"}]
這是我試過..但它是不完整的。
這個看起來不錯!我的支票 –
不錯。 len未使用。也許'使用嚴格'的功能? @xdazz – Aeoril