Javascript loop an array to find numbers divisible by 3

前端 未结 8 1160
清歌不尽
清歌不尽 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条回答
  •  暖寄归人
    2021-01-25 06:19

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

提交回复
热议问题