Difference between component.find() component.get() in Salesforce Lightning

Difference between component.find() component.get() in Salesforce Lightning

Component.get()

component.get(String key) and component.set(String key, Object value) retrieves and assigns values associated with the specified key on the component. Keys are passed in as an expression, which represents attribute values.

component.find()

find() returns different types depending on the result.

1. If the local ID is unique, find() returns the component.
2. If there are multiple components with the same local ID, find() returns an array of the components.
3. If there is no matching local ID, find() returns undefined.

component.find() works in a more broader way whereas component.get() is associated with attributes. find() method can be used to work on tags having same id’s simultaneously.

Leave a Reply