Posts

Showing posts with the label JS

Salesforce Fact #879 | Removing decimals in JS

Image
In order to remove decimals from a number in JS, we can make use of the bitwise not operator. Same can be used in LWC. Attached is an example screenshot.

Salesforce Fact #865 | Null coalescing in JS

Image
We have null coalescing operator in JS as well and it works only with null and undefined. Attached is the screenshot.

Salesforce Fact #819 | Checking duplicates in array in LWC

Many times  in LWC or JS,  we need to check if an array of primitive types contains a duplicate or not. The indexOf() method can be used to identify the same. Example: const arr = ['a', 'b', 'c', 'a']; const result = arr.filter((row, index)=>arr.indexOf(row)!=index) if(result.length > 0){     console.log('array contains duplicate'); } else{     console.log('array does not contain duplicate'); } Reference:  https://flexiple.com/javascript/find-duplicates-javascript-array

Salesforce Fact #815 | Wordcount logic in LWC

Image
We can create a simple word count logic for a long text area in LWC using some JS logic. Note: This doesn't cover consecutive spaces. Reference:  https://salesforce.stackexchange.com/questions/66249/word-count-formula#:~:text=Here%20we%20are%20counting%20the,%2C%22%20%22%2C%22%22)) Attached are the screenshots.

Salesforce Fact #641 | Array of objects destructuring in LWC

Image
While working with LWC, Sometimes we need to add some additional attribute to any object structure for any interim processing and once done, they can be removed from the objects. We can use the object destructuring of JS to remove a particular attribute from an array of objects. Attached is the screenshot.

Salesforce Fact #612 | VF: access apex data in JS methods

Image
We can access data from apex controller in JS methods in vf page. Attached are the screenshots.

Salesforce Fact #576 | Access getter in LWC JS file

Image
The getters can be accessed in JS file like the way we can access in HTML file in LWC. If we refer the api property as this.<property name> in JS file it will call the getter function. Attached is the screenshot.