Rewriting for Loop in functional language

how can I rewrite the following code into a functional language? can I use map instead of for loop? how to change it? ask God for advice

  const tempData = {name: value[j].name};
  const tempDragData = [];
  for (let k = 0; k < tempArr.length; kPP) {
    tempData[`col ${k}`] = tempArr[k].fieldName;
    tempDragData.push({id: `item-${iPP}`, name: value[j].name, content: tempArr[k].fieldName,});
  }

Apr.11,2021

const tempData = {name: value[j].name};
const tempDragData = [];
tempArr.reduce((p,c,k,a)=>{
    tempData[`col ${k}`] = c.fieldName;
    tempDragData.push({id: `item-${iPP}`, name: value[j].name, content: c.fieldName,});
})

I , j and tempArr are not given, so I just casually write down the reduce processing. As a matter of fact, it is not necessary. The efficiency of for cycle is quite high.


first of all, you need to understand what a function is

secondly, map has nothing to do with functions

finally,
map related knowledge can be found in
http://es6.ruanyifeng.com/-sharpdo.

.

knowledge of functions
https://www.zhihu.com/questio.


const { tempData, tempDragData } = tempArr.reduce((obj, item, i)=>{
  obj.tempData[`col ${k}`] = item.fieldName;
  obj.tempDragData.push({
    id: `item-${iPP}`,
    name: value[j].name,
    content: item.fieldName,
  });
  return obj;
}, {
  tempData: {
    name: value[j].name
  },
  tempDragData: []
});
Menu