Posts for Javascript

How to Filter A Collection Using Lodash

In this article, you will learn how to filter a collection using Lodash. Let’s say you have a collection of food and their availability. In order to filter a collection using Lodash, you can use the _.filter method. In this example, you will filter the collection to only list out the food that is available. […]

February 20, 2021 in Code examples

How to Hide or Show Element in Javascript

In this article, you will learn how to hide or show an element in Javascript. Let’s say you have a div element with id ‘theDIV’. html css In order to hide or show an element, you can use the document.getElementById() method and style display property, object.style.display. In this example, you will be using a button […]

February 20, 2021 in Code examples

How to Disable Button in Javascript

In this article, you will learn how to disable a button in Javascript. Let’s say you have a button element with id “theButton”. html In order to disable the button, you can use the document.getElementById() method and button disabled property, button.disabled. full html full javascript Before disabling button After disabling button Note: The document.getElementById() method […]

February 20, 2021 in Code examples

How to Deep Copy Array Using Lodash

In this article, you will learn how to deep copy an array using Lodash. Let’s say you have an array named ‘a’ with elements ‘1, 2, 3, 4’. In order to deep copy an array using Lodash, you can use the _.cloneDeep() method. Note: The _.cloneDeep() method functions by creating a fully independent yet exact […]

February 19, 2021 in Code examples

How to Capitalise First Letter in String Using Lodash

In this article, you will learn how to capitalise first letter using Lodash. Let’s say you have a string variable named ‘a’ with value “code-source.tempurl.host”. In order to capitalise first letter in string using Lodash, you can use the _.capitalize() method. Note: The _.capitalize() method functions by converting the first letter of a string to […]

February 19, 2021 in Code examples

How to Open Link in New Tab in Javascript

In this article, you will learn how to open a link in a new tab in Javascript. Let’s say you want to open a link to the code-source.tempurl.host’s homepage. In order to open a link in a new tab, you can use the window.open() method. Note: The window.open() method functions by opening the supplied link […]

February 18, 2021 in Code examples

How to Convert A String to Lowercase in Javascript

In this article, you will learn how to convert a string to lowercase letters in Javascript. Let’s say you have a string variable named ‘a’ with value “CODESOURCE.IO”. In order to convert the string to lowercase letters, you can use the toLowerCase() method. Note: The toLowerCase() method functions by converting a string to lowercase letters.

February 18, 2021 in Code examples