To determine if the childId corresponds to the parentId, you can compare the two values using a simple if statement:
if(childId === parentId) {
// The childId corresponds to the parentId
} else {
// The childId does not correspond to the parentId
}
Alternatively, if you have the parent object and you want to check if the child object belongs to it, you can use the hasOwnProperty()
method:
if(parent.hasOwnProperty(childId)) {
// The child object belongs to the parent object
} else {
// The child object does not belong to the parent object
}
Asked: 2021-11-10 11:00:00 +0000
Seen: 8 times
Last updated: Nov 02 '22