Skip to content Skip to footer

Tag: JavaScript

JavaScript

URLSearchParams returning null for the first query string

The URLSearchParams interface defines utility methods to work with the query string of a URL. const url = 'http://example.com?orderNumber=123456&pageSize=20'; const urlSearchParams = new URLSearchParams(url); console.log(urlSearchParams.get('orderNumber')); //result: null console.log(urlSearchParams.get('pageSize')); //result: 20 As shown in the above code snippet, it won't work as expected if you directly use the URL string in the URLSearchParams constructor. So the result of the first…

Read more

JavaScript

Javascript Object Property Attributes: configurable, enumerable, value, writable

In JavaScript, an object can have two types of properties: data(standard) properties and accessor properties. Every property in an object has some attributes, this blog post we are going to take a look at the attributes of data properties. The data properties have the following four attributes: [[Configurable]] – Determines whether we can change the…

Read more

JavaScript

How to loop through or enumerate the properties of a JavaScript object?

There are multiple ways to iterate/loop through all the properties in a JavaScript object.

Method 1: for-in loop


var person = {
  name: 'Shravan Kasagoni',
  age: 20,
  isActive: true
};

person.constructor.prototype.printName = function() {
  console.log(this.name);
};

person.constructor.prototype.encKey = 'somevalue';

person.constructor.prototype.printName = function() {
  console.log(this.name);
};

The for-in loop iterates over all enumerable properties of an object.


for (var propertyName in person) {
  console.log(propertyName, person[propertyName]);
}

Result:


name Shravan Kasagoni
age 20
isActive true
printName ƒ () {
  console.log(this.name);
}
encKey somevalue

Read more