Apply transform over each element without array.map()

Apply transform over each element without array.map()

For this type of transformation, we must be clear about the JS array and its methods and arguments. We also need a clear idea about the JS function. Suppose we have an integer array called numbers and some mapping functions such as plusone(which will add 1 with every element of the array), plusI(which will add the index of every element with the element), constant(only return constant), etc. So what should we do is given below.

  1. Take an array called numbers like const numbers = [1,2,3]

  2. Then we define every function with its return value. Such as const plusone = (n) => { return n+1}, const constant = () => { return 12 };

  3. We will take all elements of an array and perform a mapping function or transformation function in every element of an array and push them into a new array. We can use forEach() function for this.

  4. We will take the array and function as parameters in another function called map. We will return a new array and show them as output