How to merge arrays using spread operator in JavaScript?

Have you come across a requirement to merge two or more arrays  into another array? Let us say, you have two arrays as shown below, const metrocities = [‘Delhi’, ‘Mumbai’,’Chennai’,’Bangalore’,’Hyderabad’]; const smallcities = [‘Jamshedpur’,’Pune’,’Lucknow’,’Trivandrum’]; You need to merge them in another array with optional extra elements in the resultant array. JavaScript array spread operator makesContinueContinue reading “How to merge arrays using spread operator in JavaScript?”

How to create Private Properties in JavaScript.

We don’t have Access Modifiers in JavaScript, and all properties of an object are public, which means you can read and modify them outside the object. But what if you have a requirement to create private properties?  Consider Product object as mentioned below, let Product = { id: ‘1’, price: 200, title: ‘Pencil’ } console.log(Product.id);ContinueContinue reading “How to create Private Properties in JavaScript.”

Explain Object.keys in JavaScript

Enumerating through the properties of a JavaScript object is a persistent requirement. Hence it becomes a popular question in a JavaScript interview. Any good JavaScript developer must know about various available options. Note: You can find a video tutorial on the same at the end of the article. To start with considering the Dog objectContinueContinue reading “Explain Object.keys in JavaScript”