我寫了這段代碼,它應該解析給定的paramUnparsed(它應該是一個數組形式:[key1 = val1,key2 = val2,..,keyn = valn ])。數組長度與鍵值,js
function parseParams(paramUnparsed){
var params = [];
for (var j = 0; j < paramUnparsed.length; j++) {
if (paramUnparsed[j].split('=').length < 2) {
// error ! bad input structure, ignoring params -
params = undefined;
break; // we don't have to return error, depending
// on the function called and given params.
}
//else {
var key = paramUnparsed[j].split('=')[0];
var value = paramUnparsed[j].split('=')[1];
params[key] = value;
//}
}
console.log("In parseParams, params are: "+ concatObject(params));//DEBUG 1
console.log("In parseParams, params length is: "+ params.length);//DEBUG 2
return params;
}
我該怎麼做,並且仍然確定我創建的數組的長度?我總是在'DEBUG 2'打印輸出上得到'0'...
甜蜜!謝謝!! – Sathesh 2016-03-04 23:57:39