Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142382

Return all objects in array

$
0
0

I'm missing something super obvious here so please excuse my ignorance :(

I have a set of 5 checkboxes and would like to print out steps based on what checkbox was chosen. I'll need this for a bigger output so I'm storing the selection in it's own variable like so:

        $checkBox.find('input:checked').each(function() {
        $rec = $(this).val() + "\n";
        console.log($rec);

    }); 

Everything returns fine when I select all 5 checkboxes and check in console:

console.log

However, I want to use the output stored in $rec to use later so I did this to see what it will look like:

        $checkBox.find('input:checked').each(function() {

        $rec = $(this).val() + "\n";
        console.log($rec);

    }); 

// call rec into text input
        $textOutput.val($textOutput.val() + $rec + "\n");
        console.log($rec);

But for some reason, only the "Do Step 5" is returned when calling $rec again

second console.log

Since I'm already storing output of the 5 checkboxes in $rec why can't I access all again rather than just the last object?


Viewing all articles
Browse latest Browse all 142382

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>