0
function comm_price(comm){
list_comm = [];
k=0
var scraper = require('table-scraper');
scraper.get('http://somewebsite.com')
.then (function(tabledata){
    for(i=0;i<tabledata[14].length;i++){
        if(tabledata[14][i][1].includes(comm)){
            list_comm[k] = (tabledata[14][i]);
            k+=1;
        }
    }
    return list_comm;
});

}
var lis = [];
lis = comm_price('Pepper');

how to assign the returned data to a variable ? Im new to javascript , since there is function inside the function , im getting pretty confused in assigning the return data to a variable.

G-SON 44
  • 36
  • 2
  • you need to return something directly from `comm_price` function - but it WILL be a promise in this case, so you wont be able to `lis = comm_price('Pepper');` - unless you expect `lis` to be a Promise – Jaromanda X Apr 23 '20 at 03:49
  • `lis = comm_price('Pepper')` is empty , but when i log `list_comm` instead of return , im getting the data which i need ! @Jaromanda X – G-SON 44 Apr 23 '20 at 03:55
  • yes, did you read my comment? you don't return anything from `comm_price` - so of course lis is `undefined` .... but you can only return a promise from `comm_price` - so you'll need to rewrite your code, unless you expect `list` to be a Promise – Jaromanda X Apr 23 '20 at 05:39

0 Answers0