我正在嘗試將新值推送到數組,但是當值被推送時會創建2個新數組。我試圖將值推入一個不在單獨的數組中。我怎麼做?這是我正在使用的代碼。javascript push to 1 array
for (count = 0; count < xmlItem.length; count++) {
// dates
xmlDate = new Date(xmlItem[count].getElementsByTagName("pubDate")[0].childNodes[0].nodeValue);
// titles
xmlTitle = xmlItem[count].getElementsByTagName("title")[0].childNodes[0].nodeValue;
// descriptions
xmlDescription = xmlItem[count].getElementsByTagName("description")[0].childNodes[0].nodeValue;
// date reformated
pubDate = (xmlDate.getMonth() + 1) + "/" + xmlDate.getDate() + "/" + xmlDate.getFullYear();
// if there is a new code
if (pubDate == today) {
// array with titles for new values
totalValues = new Array();
// add the title
totalValues.push(xmlTitle);
// add badge for number of values
chrome.browserAction.setBadgeText({ text: JSON.stringify(totalValues.length) });
}
}
或'totalCodes = [];' – Don 2012-08-06 16:23:13
謝謝!工作! – 2012-08-06 16:23:45
你能接受這個答案嗎? – Kalpesh 2012-08-06 16:34:49