我有一个嵌套的表单。我想递归地验证它。在验证时,我需要检查对象是否为formcontroller类型。尝试的示例或类型时,我将其作为对象,而不是窗体控制器。请帮我找到这个。
xcitsw881#
如果你想知道一个物体是否属于某种类型,我相信你可以这样问:
person = { id: 1, name: 'John', age: 46, active: true }; house = { color: 'blue with white patterns', years: 20, isInGoodCondition: true }; const myArray = [person, house]; myArray.forEach((element) => { if (element?.name) console.log('It is a person object'); if (element?.isInGoodCondition) console.log('It is a house object'); });
person = {
id: 1,
name: 'John',
age: 46,
active: true
};
house = {
color: 'blue with white patterns',
years: 20,
isInGoodCondition: true
const myArray = [person, house];
myArray.forEach((element) => {
if (element?.name) console.log('It is a person object');
if (element?.isInGoodCondition) console.log('It is a house object');
});
这个 object?.property 安全地问是否 property 存在于对象内部。
object?.property
property
1条答案
按热度按时间xcitsw881#
如果你想知道一个物体是否属于某种类型,我相信你可以这样问:
这个
object?.property
安全地问是否property
存在于对象内部。