-2

I have a function with an if-statement. When this if-statement is triggered I want to tell another function to clear out its array.

function firstFunction(){
    if(!$myCheckBox.is(':checked')){
        secondFunction(myArray.length = 0);
    }
}

function secondFunction(myArray){
    if(myArray.length == 0){
        //Do something
    }
}
Matt
  • 74,352
  • 26
  • 153
  • 180
Reality-Torrent
  • 348
  • 3
  • 15
  • 3
    Do you mean pass in an empty array? `renderResults([]);` – Tro Sep 09 '15 at 08:13
  • Just send 0 as an argument. if you need `results` array also inside the function then send it too.. llike in the following `renderResults(0,results)` – Rajesh kannan Sep 09 '15 at 08:14
  • Simply sending 0 to the array wont work, as it does not clear out the array. And sending [] will just create a new array right? Well, I want the same array to remain, but I want to clear it of any rows within. – Reality-Torrent Sep 09 '15 at 08:17
  • [How to clear an array in JavaScript?](http://stackoverflow.com/questions/1232040/how-to-empty-an-array-in-javascript) – Anders Sep 09 '15 at 08:21
  • That is where I got results.length = 0 from – Reality-Torrent Sep 09 '15 at 08:27

1 Answers1

1

The renderResult function expects the placeholder variable. You shall send it like this:

$('#randomName').change(function() {
if(!$randomName.is(':checked')){
            // modify [results] if needed, e.g. results.length = 0;
            renderResults(results);
  • Please do not use code snippets for code not intended to actually run without extra context. Clicking run here just produce a syntax error. You can just use a code block without the run button instead. Thanks! – Anders Sep 09 '15 at 08:20