Exchanging values between functions with JavaScript

0

Hello, in my code how do I get the values contained in the "data" array when calling the function (#print) from the generateString function.

var gerarString = function () {
    var codproduto = 001,
    var newRow = 'teste',
    var iten = ([codproduto,newRow]);

    var dados = new Array();
    dados.push(iten);

    return dados;
}

$("#imprimir").on('click', function(){
    console.log(gerarString.dados);
 //$("#tabvenda").prepend(gerarString.getDados());
});
    
asked by anonymous 16.09.2016 / 21:33

1 answer

1

You have some problems with your code ... The code below shows the output console:

  

1, test

<!DOCTYPE html>
<html>
<head>
  <script   src="https://code.jquery.com/jquery-3.1.0.min.js"integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s="   crossorigin="anonymous"></script>
</head>
<body>

<button type="button" id="imprimir">Click Me!</button>

</body>
<script>
function gerarString() {
    var codproduto = 001;
    var newRow = 'teste';
    var iten = ([codproduto,newRow]);

    var dados = new Array();
    dados.push(iten);

    return dados;
}

$("#imprimir").on('click', function(){
    console.log(gerarString().toString());
 //$("#tabvenda").prepend(gerarString.getDados());
});
</script>
</html>
    
16.09.2016 / 21:49