Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从一系列数组中搜索输入标记值_Javascript_Css_Arrays_Html - Fatal编程技术网

Javascript 如何从一系列数组中搜索输入标记值

Javascript 如何从一系列数组中搜索输入标记值,javascript,css,arrays,html,Javascript,Css,Arrays,Html,我试图从一个由许多其他数组组成的数组中提取信息 我试图解决的问题是,我试图从位于各种数组中的范围中提取一个数字,但在这样做时遇到了困难 这是我的JS代码 我用Javascript创建了一个range()函数,其中列出了包含的参数(开始、结束) function rangeSCORE(start, end) { return Array(end - start + 1).fill().map((_, idx) => start + idx)

我试图从一个由许多其他数组组成的数组中提取信息

我试图解决的问题是,我试图从位于各种数组中的范围中提取一个数字,但在这样做时遇到了困难

这是我的JS代码

我用Javascript创建了一个range()函数,其中列出了包含的参数(开始、结束)

      function rangeSCORE(start, end) {
            return Array(end - start + 1).fill().map((_, idx) => start + idx)
        }


const score = document.getElementById('score').value;

const levelOneScore = rangeSCORE(486, 489);
const levelTwoScore = rangeSCORE(490, 493);
const levelThreeScore = rangeSCORE(494, 497);
const levelFourScore = rangeSCORE(498, 501);
const levelFiveScore = rangeSCORE(502, 505);
const levelSixthScore = rangeSCORE(506, 509);
const levelSeventhScore = rangeSCORE(510, 513);
const levelEightScore = rangeSCORE(514, 517);
const levelNinthScore = rangeSCORE(518, 528);

const ScoreValue = [levelOneScore, levelTwoScore, levelThreeScore, levelFourScore, levelFiveScore, levelSixthScore, levelSeventhScore, levelEightScore, levelNinthScore];

function showChance() {
    if(ScoreValue.includes(score)) {
        console.log(score)
    }
}
这是我的HTML代码

<input type="number" class="transparentBar" min="472" max="528" id="score" placeholder="SCORE">


例如,如果我输入值并单击一个按钮,我想知道如何搜索数组列表,您将受益于不同的数据结构。您希望将分数映射到级别,因此最简单的方法是创建一个数组,其中索引表示分数,相应的数组值表示级别

您可以创建这样一个数组,如下所示:

const scoreToLevel=[].concat(。。。
[485、489、493、497、501、505、509、513、517、528]。地图((结束,i,结束)=>
数组(end-(ends[i-1]| |-1)).fill(i)
)
);
//I/O处理:
const scoreInput=document.getElementById('score');
const levelOutput=document.getElementById('level');
scoreInput.addEventListener(“输入”,函数showChance(){
levelOutput.textContent=scoreToLevel[this.value];
});
得分:

级别:
将rangeSCORE定义为2D数组。所以试试这个,它会搜索rangeSCORE中的任何分数

函数范围分数(开始、结束){
返回数组(end-start+1).fill().map((\ux,idx)=>start+idx)
}
const levelOneScore=rangeSCORE(486489);
const levelTwoScore=范围分数(490493);
const levelThreeScore=范围分数(494497);
const levelFourScore=范围分数(498501);
const levelFiveScore=范围分数(502505);
const levelSixthScore=范围分数(506509);
const levelSeventhScore=范围分数(510513);
const levelEightScore=范围分数(514517);
const levelNinthScore=范围分数(518528);
const ScoreValue=[LevelOne评分、LevelTwo评分、LevelTwo评分、LevelTwo评分、LevelTwo评分、LevelTwo评分、LevelTwo评分、LevelTwo评分、LevelTwo评分、levelNinthScore评分];
函数showChance(){
const score=document.getElementById('score')。值;

对于(var i=0;i您的
Score
变量是什么,它从未定义过?我们需要您的所有代码-包括此
rangeSCORE
函数,以及您没有在问题中放入的解决问题所需的任何其他代码。@JackBashford我已经用必要的组件编辑了问题,我们仍然没有此
范围SCORE
函数。请包含它。现在看起来有两个函数-一个名为
rangeScore
,从未使用过,另一个名为
rangeScore
,它是否有不同的功能?请在发布问题时逐字发布所有相关的代码