0

I am trying to push new values to an array, but when the values are pushed 2 new arrays are created. I am trying to push the values into one array not in separate ones. How do I do that? Here is the code I am using.

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) });
  }
}

2 Answers 2

2

Move this totalCodes = new Array(); before your for loop.

Each time your for loop is iterating, it's creating new array with totalCodes = new Array();.

Sign up to request clarification or add additional context in comments.

Comments

0

Every time you execute the loop, the line totalCodes = new Array() is called, resetting totalCodes to an empty array. Declare totalCodes outside of your for loop.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.