0
var period  = document.getElementById('period').value;
        var col = element.id.split('time')[1];
        var ValueArr=[];
        for(var x= 0;x < period; x++){
            var taskValue = document.getElementById('taskDone'+x).value;
            for(var p= 0;p < taskValue; p++){
                var ValueB = document.getElementById(col+"_"+taskValue).value;
                console.log(ValueB);
                ValueArr.push(ValueB);
                //var newValue = ValueArr.sort(function (a, b) {  return a - b;  });
            }
        }
        alert(newValue);

So I have this in a function and I want to push ValueB into ValueArr. For ValueB it will be with unspecified length of numbers and with unspecified numbers but when I try I get This:https://i.sstatic.net/QqVpm.jpg

1 Answer 1

3

You have done mistake in alert. It should be alert(ValueArr); instead of alert(newValue); . That is why you are getting that error Reference error: newValue is not defined. Also you need unique elements in ValueArr, so use this code

var newValue = ValueArr.filter(function(itm, i, a) {
    return i == a.indexOf(itm);
});

Fixed code:

var period  = document.getElementById('period').value;
var col = element.id.split('time')[1];
var ValueArr=[];
for(var x= 0;x < period; x++){
    var taskValue = document.getElementById('taskDone'+x).value;
    for(var p= 0;p < taskValue; p++){
        var ValueB = document.getElementById(col+"_"+taskValue).value;
        console.log(ValueB);
        ValueArr.push(ValueB);
        var newValue = ValueArr.filter(function(itm, i, a) {
             return i == a.indexOf(itm);
        });
        //var newValue = ValueArr.sort(function (a, b) {  return a - b;  });
    }
}
alert(ValueArr);
Sign up to request clarification or add additional context in comments.

1 Comment

no, I am trying to fix the push if you see in the picture it prints what is in ValueArr after the push and I only want to have 1,2,3

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.