0

I have the following code and when I want to add the count to the beginning of the texts const so it will display in the table row.

const getters = [item => item.count, item => formatDate(item.date), item => item.num, item => item.body];
var count = 0;
  for (let row of rows) {
    count = count + 1;
    const texts = getters.map(getter => getter(row));
    //alert(count + texts)
    const rowWithCount = count + texts;
    //alert(rowWithCount);
    resultsBody.appendChild(createRowWithTexts(rowWithCount));
  }
};

what I have does not work; it displays the count but messes up the other columns.

1 Answer 1

1

When you do const rowWithCount = count + texts; you are adding number to array, in javascript it will resolve to a string, is that what you want? Or you looking to push count to your array, in this case you should do texts.push(count); and if you want for count to be first element in array you could do texts = [count].concat(texts)

Regarding number + array = string. Here is the example:

1 + [10,10] // resolves to "110,10"
Sign up to request clarification or add additional context in comments.

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.