Skip to content
Related Articles
Open in App
Not now

Related Articles

How to map array values without using map method in JavaScript ?

Improve Article
Save Article
  • Last Updated : 06 Dec, 2021
Improve Article
Save Article

Array elements can be mapped by using looping methods in JavaScript. The map() method creates a new array with the results of the output of a function called for each element of the array. This can also be implemented using for loop in JavaScript.

Approach: For this, we can create two arrays, in which one array contains the array elements that are to be mapped, and the second array stores all the return values of the corresponding function.  We can use the JavaScript Array push() method to push the return values of the function in the output array.


array.push(element1, element2, element, ... , elementN )

The Array length method can be used to find the length of the corresponding array.



Return value: Number



<!DOCTYPE html>
<html lang="en">
        JavaScript mapping using loops
        var arr = [4, 5, 10, 3, 8, 6];
        var result = [];
        let i;
        //square function returns square of a number
        const square = function(num){  
            return num*num;
        for(i=0; i< arr.length; i++){
        //Expected output: [16 ,25, 100, 9, 64, 36]

Output: The indices of the elements in the output array are shown before the numbers in the output as well as the length of the output array.

[16, 25, 100, 9, 64, 36]
0: 16
1: 25
2: 100
3: 9
4: 64
5: 36
length: 6
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!