In this tutorial, you’ll learn how to format date in JavaScript. Working with date is a common scenario when creating web applications.
JavaScript Date Time You can get the current date and time in JavaScript using the Date object.
// the following gives the current date and time objectnew Date()Using the date object you can print the current date and time.
let current_datetime = new Date()console.log(current_datetime.toString())The above code outputs the current date and time as shown:
[Read More]
How to mask characters in a string such as mask few numbers in Phone number using JavaScript ?
Let’s write a simple JavaScript method to mask characters in a string.
What we are trying to achieve, mask a phone number such as +919895590552 to +919895******
function mask(mobile_number, maskCount){ let nonMaskedNumber = mobile_number.slice(0, 0-maskCount); let maskChar = '*'.repeat(maskCount); return `${nonMaskedNumber}${maskChar}` } The above function does the job but it needs to be adjusted for certain edge cases.
[Read More]
How to remove last few characters of String using JavaScript Slice ?
Every time trim the last 6 characters from the phone number.
For example, +919895590123 and make it +919895. Now you can use slice straight away if you know where to end.
'+919895590754'.slice(0,7) // ## `+919895` But it doesn’t work is it’s different length phone number like +1219895590345.
So the solution would be to use negative index for end parameter.
[Read More]
While running Jekyll I was getting the following error, Liquid Exception: undefined method `tainted?’ for 2:Integer
The above issue occured when after a windows re install I had to re install Ruby. The issue seemed like the newer version of Ruby was not compatible with the Jekyll version(4.1.1).
I upgraded the Jekyll version to 4.3.2 and the error disappeared.
That solves the issue. But below I have described how I being a non ruby guy upgraded the Jekyll version.
[Read More]
Issue was the place where I was keeping my images folder. Images folder needed to be inside the public directory. And here is how it was referenced in the component,
While assigning variable type as Number got the following error in TypeScript, Operator ‘+’ cannot be applied to types ‘Number’ and ‘Number’
const foo = (a:Number,b: Number) => { return a+b; } So what’s wrong with the above code .Type of a and b should be number and not Number.
// ## Solution const foo = (a:number,b: number) => { return a+b; } Number in typescript is a constructor which creates Number objects.
[Read More]
How to Remove Object Property Without Using Delete Operator ?
const obj = { name : 'Roy', country : 'India', region : 'Delhi' } Object Destructuring can be used to delete a property from the above JavaScript object. Suppose you want to remove region property. You can destrcuture the obj object into two objects.
const {region, ...otherInfo} = obj; // otherinfo - {name: 'Roy', country: 'India'} Here otherInfo is your object without region.
[Read More]