map 을 써서 과제를 하던 중 특정 인덱스를 건너뛰어서 함수를 적용해야했다. 코드는 다음과 같다.
const parsing = (arr)=>{
const result = []
for(let i=1; i<arr.length; i++){
const a = {}
const key = arr[0].split(",");
const temp = arr[i].split(",");
temp.map((e,index)=>{if(index === key.length-1) return; a[key[index].trim()] = e})
result.push(a);
}
return result;
}
temp.map((e,index)=>{if(index === key.length-1) return; a[key[index].trim()] = e}) 를 다음에 쓰기 좋게 일반화 해보고자 한다.
arr.map((element, index)=>{if(index === 10)return; callback()})
사용 예제)
arr = [0,1,2,3,4,5,6,7,8,9];
arr.map((element, index)=>{if(index === 2)return; console.log(element)})
잘 작동한다.
오! 대박 좋은거 알게되었습니다. 감사합니다👍👍