Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.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_Algorithm_Iteration - Fatal编程技术网

Javascript 每次移动到下一个迭代

Javascript 每次移动到下一个迭代,javascript,algorithm,iteration,Javascript,Algorithm,Iteration,我有一个名为current的变量,它存储数字0和长度为4的数组。我想迭代数组,然后一次一个地将其添加到当前变量中。如果第一个变量未通过,请移动到下一个变量。我如何实现这一点请帮助!!!例如: /*2 0 7 0 11 0 15 0*/ if not try the next one: /*2 1 7 1 11 1 15 1*/ so on and so forth let nums = [2,7,11,15] let

我有一个名为current的变量,它存储数字0和长度为4的数组。我想迭代数组,然后一次一个地将其添加到当前变量中。如果第一个变量未通过,请移动到下一个变量。我如何实现这一点请帮助!!!例如:

    /*2 0
      7 0
      11 0
      15 0*/

if not try the next one:

  /*2 1
    7 1
    11 1
    15 1*/
so on and so forth

let nums = [2,7,11,15]
let target = 18
let current = 0

nums.forEach(function(k,i){
let begin = current
if(nums[begin]+nums[i] === target){
  console.log(true)
}else{
begin++
}
console.log(nums[begin],nums[i])

})
让nums=[2,7,11,15]
,目标=18
,标志=0
,i,j
;
对于(i=0;i

让nums=[2,7,11,15]
,目标=18
,i,j,found=false
;

对于(i=0;iGreat,如果这有效,请在@Aliayub Ali上投一票