首页 > 解决方案 > 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; 
            };

标签: javascriptindexing

解决方案


推荐阅读