Search By Label
export const displayRoute = (route: string, t: (key: string) => string): string => { const accountDetailRegex = /^\/accounts\/[0-9a-fA-F-]{36}$/;
if (accountDetailRegex.test(route)) return t('accountDetails'); };
.replace()
to match everything from the start of your string up until the first dot .
, and replace that with an empty string.var str = "P001.M003.PO888393";
var res = str.replace(/^[^\.]*\./, '');
console.log(res);
#=> M003.PO888393
arr = new Array(3).fill(0)
let original = { a: 1, b: { c: 2 } } let copy = { ...original } copy.b.c = 3 // Changes "original.b.c"
let original = { a: 1, b: { c: 2 } } let copy = JSON.parse(JSON.stringify(original)); copy.b.c = 3 // The "original.b.c" remains 2
console.dir(body, { depth: null });
//example const double = (x) => x * 2; const square = (x) => x * x; var output1 = double(2); var output2 = square(output1); console.log(output2); var output_final = square(double(2)); console.log(output_final);
process.nextTick()
is a function in Node.js designed to schedule a callback function to be invoked in the next iteration of the event loop. const validPwd = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])([A-Za-z\d$@$!%*?&]|[^ ]){8,}$/;
const getPwdAndValidate = (pwdField, pwdField2) => { const validPwd = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])([A-Za-z\d$@$!%*?&]|[^ ]){8,}$/; if (pwdField === pwdField2 && validPwd.test(pwdField) && pwdField.length >= 8) { return pwdField; } else { return null; } };
const myMap = new Map();myMap.set('name', 'John');
myMap.set('age', 30);console.log(myMap.get('name')); // Output: 'John'
console.log(myMap.get('age')); // Output: 30
const number = 123456.789;console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number));
// Expected output: "123.456,79 €"// The Japanese yen doesn't use a minor unit
console.log(new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(number));
// Expected output: "¥123,457"// Limit to three significant digits
console.log(new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }).format(number));
// Expected output: "1,23,000"
// Start the timer console.time('myTimer');// Simulate a time-consuming operation
for (let i = 0; i < 1000000; i++) {
// Some code here
}// Stop the timer and display the elapsed time in milliseconds
console.timeEnd('myTimer');
const person = { firstName: "John", lastName: "Doe", age: 30, address: { street: "123 Main St", city: "Anytown", state: "CA", zip: "12345", }, };console.dir(person);/* output: Object age: 30 address: Object city: "Anytown" state: "CA" street: "123 Main St" zip: "12345" firstName: "John" lastName: "Doe" */
async function* fetchUsers() { let page = 1; const perPage = 10; // Number of users per page
while (true) { const response = await fetch(`https://api.example.com/users?page=${page}&per_page=${perPage}`); const users = await response.json();
if (users.length === 0) { // No more users to fetch break; }
for (const user of users) { yield user; }
page++; } }
// Usage:
const userGenerator = fetchUsers();(async () => {
for await (const user of userGenerator) {
console.log(`User: ${user.name}, Email: ${user.email}`);
}
})();