Check if an Object is an Array in JavaScript

Abdul Rawoof
Updated on 26-Aug-2022 11:59:58

287 Views

Array is a data type which can store multiple elements of similar data types. For example, if an array is declared as integer data type then it stores one or more elements of the integer data type. To check if the given object or to know the data type, we can use directly the typeof() method in JavaScript. Using typeof() method typeof() is a function which gives the type of the given object. The typeof() will return a string which is the data type of the given operand. The operand can be an object, a variable or a function. For ... Read More

Instanceof Operator in JavaScript

Abdul Rawoof
Updated on 26-Aug-2022 11:59:38

1K+ Views

The Instanceof operator in JavaScript checks for the type of object at the run time environment. The result it returns is of Boolean type i.e., if the given input object is same as the object for which it is being checked, then it returns “true” or else it returns “false”. Syntax The syntax of Instanceof operator is shown below − var myVar = nameOfObject instanceof typeOfObject Instanceof operator is used in JavaScript for a unique purpose. As in JavaScript some of the variables are declared without mentioning the type of variable or the data type. In C, C++, Java ... Read More

Check Existence of Key in JavaScript Object or Array

Abdul Rawoof
Updated on 26-Aug-2022 11:59:20

11K+ Views

In JavaScript an object is found to be in the form of key value pairs. The keys of the objects are known as properties of the given object and is represented using a string. The property of the object can have a value which can be of any data type. For example, if an employee object is created then it has the properties like employee name, employee id, employee age, salary etc. These are the properties of the employee object which are called keys. The values of these properties will be different for different employees. In case of array, the ... Read More

JavaScript Values for Nothing

Abdul Rawoof
Updated on 26-Aug-2022 11:58:57

699 Views

JavaScript has two values for nothing i.e., null and undefined. These two are also the primitive types in JavaScript. Undefined Out of the two values, Undefined in JavaScript means if a variable is declared and no value is assigned to the variable, then this variable is said to be undefined. An object can also be null. It is said to be null when there is no value to it. Example 1 This example of the undefined value in JavaScript. var str console.log('The value of given variable is:', str) In the above example 1, a variable named ‘str’ is declared. ... Read More

Find Operating System in Client Machine Using JavaScript

Abdul Rawoof
Updated on 26-Aug-2022 11:58:35

1K+ Views

The type of operating system used in the client machine can be detected using some of the functions in JavaScript. The different functions are discussed below. Using navigator.appVersion This property will return the information about the browser and the operating system being used in the form of a string. Syntax The syntax for the navigator.appVersion is given below. navigator.appVersion Example 1 This example demonstrates the usage of navigator.appVersion to detect client OS − Click to get the operating system Operating System ... Read More

Use of Clear Method in JavaScript WeakMap

Abdul Rawoof
Updated on 26-Aug-2022 11:58:18

560 Views

WeakMap is a collection in JavaScript. This type of collection is used to store the data in the form of key-value pairs. In WeakMap, the key must be definitely an object and the values can be of any type. This collection is called as WeakMap because of the key which is mandated to be the object. An object can be garbage collected which is a disadvantage when compared with Map. In JavaScript WeakMap, clear() function is used to delete the whole weakMap or removes all the elements in the weakMap. Syntax the syntax for weak map is as follows. mapName.clear() ... Read More

Methods of WeakMap Instances in JavaScript

Abdul Rawoof
Updated on 26-Aug-2022 11:58:00

127 Views

WeakMap is a collection in JavaScript. This type of collection is used to store the data in the form of key-value pairs. In WeakMap, the key must be definitely an object and the values can be of any type. New function in weakMaps A new WeakMap is created using the ‘new’ key word dynamically. Syntax A new WeakMap is created using the syntax mentioned below. var weakMapName = new WeakMap() Example 1 This example demonstrates how to create a WeakMap using new operator in JavaScript − var wkMap = new WeakMap() if(wkMap){ console.log("WeakMap is created using ... Read More

Why We Need WeakMaps in JavaScript

Abdul Rawoof
Updated on 26-Aug-2022 11:57:42

437 Views

WeakMap is a collection in JavaScript. This type of collection is used to store the data in the form of key-value pairs. In WeakMap, the key must definitely be an object and the values can be of any type. The difference between a Map and a WeakMap is, in weakmap key must be an object and the other difference is that a weakmap is like a blackbox where the keys can’t be retrieved. The value of the weakmap can be accessed only if the key is known which means the values in the weakmap are private. Additional data can be ... Read More

Most Efficient Way to Deep Clone an Object in JavaScript

Abdul Rawoof
Updated on 26-Aug-2022 11:57:23

1K+ Views

In JavaScript, objects are the collection of a key value pairs. The properties of the object are the keys and is denoted with a string. The value of the key is the value of the property of the given object. In JavaScript, the objects can be copied to other by many ways in which some of them are discussed below. Using spread operator(…), Using assign() function and Using JSON.parse() and JSON.stringify() functions. Using the Json.parse() and Stingify() methods Among the above mentioned three ways, for an object to be deep cloned, JSON.stringify() and JSON.parse() functions are used. ... Read More

Use of Window Location in JavaScript

Abdul Rawoof
Updated on 26-Aug-2022 11:57:03

2K+ Views

Window.location is the location property of a window and it is a reference to a Location object; it represents the current URL of the document being displayed in that window. Since window object is at the top of the scope chain, so properties of the window.location object can be accessed without window. prefix, for example window.location.href can be written as location.href. The following section will show you how to get the URL of page as well as hostname, protocol, etc. using the location object property of the window object. You can use the window.location.href property to get the entire URL ... Read More

Advertisements