// simplest function definition in js 😁
let e = e => +e
let e = e => +e
// Js Own event lib creation
/*
For use:
e = new EventEmitter();
e.on("mes", (mes)=> {
console.log("logic here")
})
e.emit("mes", {data: "mydata"})
*/
class EventEmitter {
funcs = [];
constructor() {}
on(mesType, callback) {
this.funcs.push({ mesType, callback });
}
emit(mesType, obj) {
this.funcs.forEach(funobj => {
if (funobj.mesType == mesType) {
funobj.callback(obj);
}
});
}
}/*
For use:
e = new EventEmitter();
e.on("mes", (mes)=> {
console.log("logic here")
})
e.emit("mes", {data: "mydata"})
*/
👍1
All video downloader js libraries:
Youtube video downloader
https://www.npmjs.com/package/ytdl-core
Insta video downloader
https://www.npmjs.com/package/snapsave-downloader-itj
Facebook video downloader
https://www.npmjs.com/package/fb-downloader-scrapper
Twitter video downloader
https://github.com/JBLorincz/xvidrip
Or
Twitter video downloader
https://www.npmjs.com/package/video-url-link?activeTab=code
Youtube video downloader
https://www.npmjs.com/package/ytdl-core
Insta video downloader
https://www.npmjs.com/package/snapsave-downloader-itj
Facebook video downloader
https://www.npmjs.com/package/fb-downloader-scrapper
Twitter video downloader
(If you have chrome then use update it in puppeteer-core)
https://github.com/JBLorincz/xvidrip
Or
Twitter video downloader
(Without puppeteer Old lib so needs some modification as twitter is now x.com)
https://www.npmjs.com/package/video-url-link?activeTab=code
👍1
// Js code to scrap phone numbers from string
str = "+911234567890 xyz abcd Xs bdtsk yts ki hrtsk 1212343409 djdb 23 yted l 1234567 Ynd yts"
console.log(str.match(/\+?\d{10,12}/g))
Javascript loops
for loop: It's used when you know the number of iterations. It consists of three parts: initialization, condition, and iteration statement.
while loop: It executes a block of code while a specified condition is true.
do...while loop: Similar to a while loop, but it always executes the block of code at least once, and then checks the condition.
for...in loop: Iterates over the enumerable properties of an object.
for...of loop: Introduced in ES6, it iterates over iterable objects (arrays, strings, maps, sets, etc.).
@nodejs_codes_pro
for loop: It's used when you know the number of iterations. It consists of three parts: initialization, condition, and iteration statement.
for (let i = 0; i < 5; i++) {
console.log(i)
}while loop: It executes a block of code while a specified condition is true.
let i = 0;
while (i < 5) {
console.log(i)
i++;
}
do...while loop: Similar to a while loop, but it always executes the block of code at least once, and then checks the condition.
let i = 0;
do {
console.log(i)
i++;
} while (i < 5);
for...in loop: Iterates over the enumerable properties of an object.
const obj = { a: 1, b: 2, c: 3 };
for (let prop in obj) {
// Code to be executed
console.log(prop + ': ' + obj[prop]);
}for...of loop: Introduced in ES6, it iterates over iterable objects (arrays, strings, maps, sets, etc.).
const arr = [1, 2, 3];
for (let value of arr) {
console.log(value);
}
@nodejs_codes_pro
👍2
// Word count in string
require("jsshort").input("Enter string: ")
.then((Str)=>{
obj = {}
for(let x of Str)
obj[x] = (obj[x]||0) + 1
console.log(obj)
})// 1. push()
let arrPush = [1, 2, 3];
arrPush.push(4, 5);
console.log(arrPush); // Output: [1, 2, 3, 4, 5]
// 2. pop()
let arrPop = [1, 2, 3, 4, 5];
let popped = arrPop.pop();
console.log(popped); // Output: 5
console.log(arrPop); // Output: [1, 2, 3, 4]
// 3. shift()
let arrShift = [1, 2, 3, 4, 5];
let shifted = arrShift.shift();
console.log(shifted); // Output: 1
console.log(arrShift); // Output: [2, 3, 4, 5]
// 4. unshift()
let arrUnshift = [1, 2, 3];
arrUnshift.unshift(-3, -2, -1, 0);
console.log(arrUnshift); // Output: [-3, -2, -1, 0, 1, 2, 3]
// 5. splice()
let arrSplice = [1, 2, 3, 4, 5];
arrSplice.splice(2, 1, 'a', 'b');
console.log(arrSplice); // Output: [1, 2, 'a', 'b', 4, 5]
// 6. slice()
let arrSlice = [1, 2, 3, 4, 5];
let sliced = arrSlice.slice(1, 4);
console.log(sliced); // Output: [2, 3, 4]
// 7. concat()
let arrConcat1 = [1, 2, 3];
let arrConcat2 = [4, 5];
let concatenated = arrConcat1.concat(arrConcat2);
console.log(concatenated); // Output: [1, 2, 3, 4, 5]
// 8. indexOf()
let arrIndexOf = [1, 2, 3, 4, 5, 4];
let index = arrIndexOf.indexOf(4);
console.log(index); // Output: 3
// 9. lastIndexOf()
let arrLastIndexOf = [1, 2, 3, 4, 5, 4];
let lastIndex = arrLastIndexOf.lastIndexOf(4);
console.log(lastIndex); // Output: 5
// 10. includes()
let arrIncludes = [1, 2, 3, 4, 5];
let included = arrIncludes.includes(3);
console.log(included); // Output: true