Found 6710 Articles for Javascript

Super keyword in JavaScript?

Lokesh Yadav
Updated on 09-Dec-2022 10:09:56

1K+ Views

In this article, we are going to discuss about the super keyword in JavaScript with suitable examples. The Super keyword is basically used in Object Oriented Programming. The Super keyword is used to call parameters and functions of an object’s parent. There are times a parent class and sub class can have same method names and parameter names. In those case, to avoid confusion between the parent class and sub class method names or parameter names, super keyword is used. In order to use a Super keyword, the child method must extend the parent class method. Syntax The syntax to ... Read More

JavaScript Sleep() function?

vineeth.mariserla
Updated on 02-Sep-2023 12:26:06

53K+ Views

Sleep()With the help of sleep() we can make a function to pause execution for a fixed amount of time. In programming languages such as C and PHP we would call sleep(sec). Java has thread.sleep(), Python has time.sleep() and Go has time.Sleep(2 * time.Second).JavaScript doesn't have these kinds of sleep functions. But we should thank promises and async/await function in ES 2018. Because these features have helped us to use sleep() as easy as possible. Let's discuss it in a nutshell.syntax-1sleep(Time in ms).then(() => { //// code })We can use the sleep function with then call back as shown above.syntax-2const work = async () => { await sleep(Time in ... Read More

Object.assign() in JavaScript?

vineeth.mariserla
Updated on 20-Aug-2019 14:42:35

681 Views

Object.assign()This method is used to copy one or more source objects to a target object. It invokes getters and setters since it uses both 'get' on the source and 'Set' on the target. It returns the target object which has properties and values copied from the target object. This method does not throw on null or undefined source values.syntaxObject.assign(target, ...source objects);It takes source objects and a target object as parameters and push the source objects into the target object and display the target object.Example-1In the following example, the properties from the source objects  "obj1", "obj2", and "obj3" were pushed into ... Read More

Execute digits in even places in a JavaScript array?

Lokesh Yadav
Updated on 09-Dec-2022 10:08:19

167 Views

In this article, the given task is to execute digits in even places in a JavaScript array with suitable examples. To execute the digits in even places in a JavaScript array, we need to get the starting index of the array and we need to loop through it by checking whether the index is at odd place or even place. Using the filter() Method: This method will create a new array filled with elements that pass a test provided by a specified function. This method doesn’t execute the function for empty elements and this method do not modify the original ... Read More

Use of 'weakMap.has()' method in JavaScript?

Manisha Patil
Updated on 23-Aug-2022 14:26:38

155 Views

The key-value pairs are stored using JavaScript WeakMap Objects. A WeakMap object differs from a Map object in that such objects should be weakly referred and "object" should be stored in the WeakMap object as a key. In comparison, you can add simple values like strings, booleans, symbols, and numbers to the Map objects. WeakMap objects are stored loosely, therefore if the references to a particular key are dropped or the object is erased, the garbage collection will drop the WeakMap element after it has verified that the value is mapped to the relevant object. The JavaScript built-in function weakMap.has() ... Read More

First element and last element in a JavaScript array?

vineeth.mariserla
Updated on 20-Aug-2019 08:19:15

772 Views

An array is a group of elements. Each element has its own index value. We can access any element using these indexes. But in the case of the last element, we don't know the index until we know the number of elements present in the array. In this case, we have to use logic. Let's discuss these details in a nutshell.Accessing the first elementSince we know the index of the first element we can get the value of that element very easily. Let the array be arr. then the value of the first element is arr[0].ExampleIn the following example, there are ... Read More

Get the first and last item in an array using JavaScript?

Ayush Gupta
Updated on 16-Sep-2019 07:32:55

318 Views

Javascript arrays are 0-indexed. This means that the first element is at the 0th position. The last element is at the length-of-array - 1th position. So we can access these elements using −Examplearr[0] // First element arr[arr.length - 1] // last element For example, let arr = [1, 'test', {}, 'hello'] console.log(arr[0]) console.log(arr[arr.length - 1])Output1 hello

How "getElementByID" works in JavaScript?

Lokesh Yadav
Updated on 12-Nov-2024 17:48:07

7K+ Views

This article discusses about how “getElementByID” method work in JavaScript. The getElementByID() method in JavaScript is a document method. When we give a specific string which should match the ID of the HTML element, it returns the element object. Every HTML element can be assigned a unique ID. If two or more elements have the same ID, then the getElementByID() method returns the first element. The getElementByID() method is used for the faster access of an element. It helps us to manipulate an HTML element within our document and is supported by all the modern browsers. If the element is ... Read More

Shift() vs pop() methods in JavaScript?

Manisha Patil
Updated on 23-Aug-2022 13:25:47

2K+ Views

To remove an element from an array with JavaScript, use the shift() and pop() functions. However, there is a slight distinction among them. While pop() removes the last element from an array, shift() removes the first element from an array. When using the shift() method, the value that was deleted is returned after the element at the zeroth position is removed and values at subsequent indexes are shifted downward. The return value is undefined if the length property is 0. A function that modifies data is shift(). Both the substance and the length of this are altered. Use arr.slice(1) instead ... Read More

Document.title() use in JavaScript?

Manisha Patil
Updated on 23-Aug-2022 13:35:39

7K+ Views

The document's current title can be obtained or changed using the document.title attribute. When present, the value of the is used by default. You can change or get the current title of the document using the document.title attribute. By providing a new title as a string to this attribute, the page's title can be changed. The chosen title will immediately be reflected in the website's title. In this article you will see two types of methods used to change or use Document.title() use in JavaScript Using the document.title property − You may set or get the current title ... Read More

Advertisements