나는 이것이 어디에서 잘못 될지 정말로보고 있지 않습니다. O'Reilly의 Learning React에서 Bank : & Porcello에 의해이 특정 사례의 게시물을 보았습니다. 그러나 게시물은 제대로 작동하는 것으로 보이지만 예제는 그렇지 않습니다. 오타가 있다면, 나는 그것을 보지 못합니다. 내 결함은 어딨어? 내가 대신 빈을 떠난, 당신은 이름에 대한 새 값을 추가하지 않은확산 연산자가있는 맵()이 작동하지 않는 이유는 무엇입니까?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
</head>
<body>
<script type="text/babel">
// Editing one object in an array of objects
let schools = [
{name: 'Yorktown'},
{name: 'Stratford'},
{name: 'Washington & Lee'},
{name: 'Wakefield'}
];
const editName = (oldName, newName, arr) =>
arr.map(item => {
if (item.name === oldName) {
return {
...item,
name
}
}
else {
return item
}
});
let updatedSchools = editName('Stratford', 'HB Woodlawn', schools);
console.log(updatedSchools[1]); // name: ""
console.log(schools[1]); // name: "Stratford"
</script>
</body>
</html>
참고 : '...'은 연산자가 아닙니다. (그리고 누군가가 말하기 전에 : MDN 페이지의 URL을 무시하면 페이지를 만든 사람이 잘못한 것입니다.) –
ummm,'...'은 스프레드 연산자 오른쪽입니까? – illiteratewriter