Javascript 列和行的值

Javascript 列和行的值,javascript,loops,foreach,bitcoin,cryptocurrency,Javascript,Loops,Foreach,Bitcoin,Cryptocurrency,我在GoogleSheets中使用这个脚本从中提取数据。我添加了一个循环(coins.forEach),只需对API进行一次调用即可获得所需硬币的所有数据(有限积分)。但是在每个循环/硬币之后,它在列中持续下降,我想为每个硬币使用一个新列 我如何做到这一点,而不需要为每一枚硬币再次调用函数(和API)?我希望我说清楚了,我不记得我从哪里得到了原始剧本 函数cmc(){ var响应=CMCFetch(); 如果(response.status==true){response.data=respo

我在GoogleSheets中使用这个脚本从中提取数据。我添加了一个循环(
coins.forEach
),只需对API进行一次调用即可获得所需硬币的所有数据(有限积分)。但是在每个循环/硬币之后,它在列中持续下降,我想为每个硬币使用一个新列

我如何做到这一点,而不需要为每一枚硬币再次调用函数(和API)?我希望我说清楚了,我不记得我从哪里得到了原始剧本

函数cmc(){
var响应=CMCFetch();
如果(response.status==true){response.data=response.datos;
}  
返回response.data;}
函数xcmfetch(){
var uri=”https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?CMC_PRO_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
cache=CacheService.getScriptCache(),
响应={状态:true,名称:“未知”,USD:0,BTC:0,datos:[],错误:null},
obj_数组=空;
obj_array=JSON.parse(cache.get('firstX');
if(obj_数组===null)
{试试{
obj_array=JSON.parse(UrlFetchApp.fetch(uri.getContentText());
cache.put('firstX',JSON.stringify(obj_数组),20);}/**缓存20秒
catch(e){response.status=false;response.error=e}
var硬币=[“btc”、“eth”、“ltc”、“bch”];
如果(response.status==true){
硬币。forEach(功能(符号){
for(obj_数组中的r.data){
if(obj_array.data[r].symbol==symb.toUpperCase()){
response.datos.push(
obj_阵列。数据[r]。总供给,
obj_数组。数据[r]。cmc_秩,
obj_数组.数据[r].quote.USD.market_cap,
obj_数组。数据[r]。quote.USD.volume_24小时,
parseFloat(obj_数组.data[r].quote.USD.percent_change_7d),
parseFloat(obj_数组.data[r].quote.USD.percent_change_24小时),
parseFloat(obj_数组.data[r].quote.USD.percent_change_1h),
obj_数组.数据[r].quote.USD.price
);
break;}}}}}
返回响应;

}
我想问题在于(obj_array.data中的r)。 这意味着您正在遍历每个对象的属性。 因此不能调用
obj_array.data[r].symbol
。 将其替换为for(int r=0;r

我将for(r in obj_array.data)替换为for(int r=0;r并显示错误“缺失;在for循环初始值设定项之后-第27行”我的意思是,代码工作得很好,我只想将数据分成不同的行和列,而不仅仅是一个长列