Thursday, 3 August 2023

Javascript: Interview Question: How to filter even numbers from Array without using predefined filter in Javascript?

 Javascript: Interview Question: How to filter even numbers from Array without using predefined filter in Javascript?



Solution: By using for loop .. we can achieve this easily

let arrNums = [46,10,21, 56, 89, 67, 33, 87, 34, 98, 76, 88, 65, 12, 19, 10, 15, 17, 18,22];

let evenNums = [];

for(let i=0;i<=arrNums.length;i++){

    if (arrNums[i] % 2 === 0) {

        evenNums.push(arrNums[i]);

   }

}

console.log(evenNums)


Out Put : 

[46, 10, 56, 34, 98, 76, 88, 12, 10, 18, 22]

Quick Solutions

More

About Us

I specialize in designing and developing dynamic websites, web applications, and other web-related projects. My expertise includes working with Java, .NET, PHP, and developing Android apps.

Contact Us

Sharath Babu
Company : SLS Tech Services.
URL : SLS Tech Services
Top