javascript - Javscipt 从一个索引转到另一个索引
问题描述
从一个索引号到另一个索引号的 JavaScript 语法是什么?我在问这个 Python 代码的 JavaScript 等价物:c[3:6]
我最终想要做的是将 100 个值的“A”列表附加到列表“B”,然后将计数器递增 100,因此当用户单击按钮时,计数器会递增并且现在附加 A 列表从第 100 位到第 200 位列表 B 的索引。每次用户点击按钮时,都会如此。
var counter = 0;
var means = [];
var hundredmeans = [];
var growingmeans = [];
var popMean=100;
var standard = gaussian(popMean, 5);
function makeAndPlotManySamples()
{
var sample = [];
for (i = 0; i<100; i++){
for (j = 0; j<sampleSize; j++){
sample[i] = standard()
}
hundredmeans[i] = average(sample)
}
growingmeans[counter::counter+100].append = (hundredmeans)
var trace = {
x: sample,
name: 'Data',
type: 'histogram',
xbins: {
end: 120,
size: 0.05,
start: 80
}
};
var layout = {
xaxis:{
title: 'One of the one hundred samples',
range: [80, 120]
},
yaxis: {range:[0,Math.max(10,Math.floor(sampleSize/10))]}
};
var data3 = [trace];
Plotly.newPlot('oneSample', data3, layout);
var trace2 = {
x: growingmeans,
name:'Data',
type: 'histogram',
xbins: {
end: 120,
size: 0.05,
start: 80
}
};
var layout2 = {
xaxis: {
title: 'The distribution of the means of the samples',
range: [80, 120]
},
yaxis:{range:[0,30]}
};
var data4 = [trace2];
Plotly.newPlot('sampleMeans', data4,layout2);
counter=counter+100;
};
解决方案
推荐阅读
- flutter - 颤动:BLoC Builder 未更新,尽管我在调试器中看到新的/不同的状态
- ios - 如何处理persistentContainer加载失败的情况
- javascript - 为什么我的外部 javscript onclick 不起作用
- ionic-framework - Ionic v5 - 离子幻灯片如何改变分页位置
- angular - 如何让 * ngFor 生成的每个输入都有自己的表单控件
- python - 测试文件夹中的相对导入:ImportError
- python - 是否可以在不使用 paypal_dict 表单的情况下集成 Django Paypal IPN?
- javascript - 从 innerHTML 列表中的按钮获取元素ById
- python - 使用 BeautifulSoup Python 找不到 HTML 元素
- .net - 在 Parallel.ForEach 中运行更新查询时,在 .NET 中取消了雪花 SQL 执行