Input: [1, 2, 3] . Output should be [2,3,4] without mutating array. How to make it dynamic as 1 is hardcode . | JS, TS, React and Angular Forum
J
JYOTI SHARMA Posted on 21/01/2022

Note: I have done almose

 

var newArray = [];

var arr=[1, 2, 3];


function map(arr, callback) { // arr=[1, 2, 3], callback=function (x) { return x + 1; }

arr.forEach(function(index,value,arr){
    newArray[value] = index + 1;
}

);
console.log(newArray);
}