javascript - Loop an array in Google Apps Scripts -
i'm trying write loop array getting invalid string error.
if keyword = "mesothelioma|seo"
function json(keyword) { var jsondata = urlfetchapp.fetch("http://api.grepwords.com/lookup?apikey=carterq="+keyword); var object = utilities.jsonparse(jsondata.getcontenttext()); var results = array("error", "error", "error", "error"); (var = 0; < object.length; i++) { results[0] = object[0].cpc; results[1] = object[0].cmp; results[2] = object[0].lms; results[3] = object[0].m1; } return results; }
any thoughts?
your reference error coming line:
var jsondata = urlfetchapp.fetch("http://api.grepwords.com/lookup?apikey=carter&q="+keyword);
from above code, moment use 'keyword'. sure returns correct information? , if have thought loop?
suppose var object = utilities.jsonparse(jsondata.getcontenttext());
returns this:
var object = [ {cpc: 'test1', cmp: 'test2', lms: 'test3', m1: 'test4'}, {cpc: 'test5', cmp: 'test6', lms: 'test7', m1: 'test8'}, {cpc: 'test9', cmp: 'test10', lms: 'test11', m1: 'test12'} ];
and use loop:
(var = 0; < object.length; i++) { results[0] = object[0].cpc; results[1] = object[0].cmp; results[2] = object[0].lms; results[3] = object[0].m1; }
you realize never use 'i'? , overwrite had in results same thing after each loop? sure wanted this?
here jsfiddle: http://jsfiddle.net/grimbode/96gwh/1/
Comments
Post a Comment