배열과 객체를 입력받아 배열의 각 요소들을 객체의 키로 했을 때 그 값을 추출하여 만든 새로운 객체를 리턴해야 합니다.
const arr = ['a', 'c', 'e'];
const obj = { a: 1, b: 2, c: 3, d: 4 };
let output = select(arr, obj);
console.log(output); // --> { a: 1, c: 3 }
function select(arr, obj) {
// TODO: 여기에 코드를 작성합니다.
let newA={};
객체를 전달해줌
for(let prop in obj ){
배열을 전체돌아줌.
for(let i=0; i<arr.length; i++){
전체돌고 배열에[i]=== 객체a 랑 같냐?
if(arr[i]===prop){
같으면 newA[prop] 에 삽입
newA[prop]=obj[prop];
}
}
}
return newA;
}