코딩/React 본 캠프

[본 캠프 11일차] 걷기반 3회차 수업

James Song 2024. 7. 29. 11:06
반응형

const testArr = [
  {
    name: "홍길동",
    age: 21,
  },
  {
    name: "홍길순",
    age: 23,
  },
  {
    name: "김르탄",
    age: 40,
  },
];

  testArr.forEach(function (obj) {
    console.log(obj.name);
  });


const people = [
  {
    id: 1,
    name: "홍길동",
    age: 30,
  },
  {
    id: 2,
    name: "홍길순",
    age: 15,
  },
  {
    id: 3,
    name: "김르탄",
    age: 16,
  },
];

// 배열 복사
const newPeople = people.map(function (person) {
  const newPerson = {
    id: person.id,
    name: person.name,
    age: person.age,
    isAdult: person.age >= 20,
  };

  return newPerson;
});
console.log(newPeople);


const testArr = ["윤창식", "최원장", "김병연", "박가현"];

const newArr = testArr.map(function (이름) {
  const 새로운객체 = {
    name: 이름,
    job: "tutor",
  };

  return 새로운객체;
});

console.log(newArr);


const tutors = [
  {
    name: "윤창식",
    job: "tutor",
  },
  {
    name: "최원장",
    job: "developer",
  },
  {
    name: "김병연",
    job: "tutor",
  },
  {
    name: "박가현",
    job: "tutor",
  },
];
const realTutors = tutors.filter(function (t) {
  //   if (t.job === "tutor") {
  //     return true;
  //   } else {
  //     return false;
  //   }
  return t.job === "tutor";
});
console.log("realTutors => ", realTutors);

반응형