Javascript loop an array to find numbers divisible by 3

前端 未结 8 1241
清歌不尽
清歌不尽 2021-01-25 05:41

I am needing to find the correct way to have javascript loop through an array, find all numbers that are divisible by 3, and push those numbers into a new array.

Here is

8条回答
  •  萌比男神i
    2021-01-25 06:21

    Check if the number is divisible by 3 if so then add it to array. Try this

    function loveTheThrees(array) {
        for (i = 0, len = array.length; i < len; i++) {
          if(array[i] % 3 == 0){
            three.push(array[I]);
         }
      }
    

提交回复
热议问题