爲什麼數組解析不起作用?解析數組一半
var input = [ 'sam 99912222',
'tom 11122222',
'harry 12299933',
'sam',
'edward',
'harry' ];
var numItems = 3;
console.log(input);
var phoneNames = [];
var searchNames = [];
var phoneBook = [];
for (i = 0; i < numItems; i++) {
phoneNames.push(input[i]);
var j = i + numItems;
searchNames.push(input[j]);
}
console.log("phoneNames: " + phoneNames);
console.log("searchNames: " + searchNames);
輸出:
[ 'sam 99912222',
'tom 11122222',
'harry 12299933',
'sam',
'edward',
'harry' ]
phoneNames: sam 99912222,tom 11122222,harry 12299933
searchNames: ,,
爲什麼searchNames未填充值?
有多大你的輸入數組?索引j是否大於輸入數組的大小? – auburg
如果您單擊「運行代碼段」按鈕,您將看到輸出如預期。無論您的實際輸入或您的實際代碼是別的。 – JJJ
查看代碼片段,searchNames在@JJJ上填上 – havenchyk