标签: javascript arrays reactjs
let check = false persons.forEach((person, i) => { check = check || newName === person.name }) if(check){ window.alert(`${newName} is already added to the phonebook`) return }
persons是一个状态数组,其中包含对象{name:'name'}