Javascript Node Js basic to Advance
1.09K subscribers
4 photos
1 video
2 files
39 links
Javascript Node Js group

@LogicB_Support
@BCA_MCA_BTECH
Download Telegram
// 13. padEnd()
(async () => {
let { input } = require("jsshort");
let strPadEnd = await input("Enter a string: ");
let targetLengthEnd = parseInt(await input("Enter target length: "));
let padStringEnd = await input("Enter padding string: ");
console.log(strPadEnd.padEnd(targetLengthEnd, padStringEnd));
})();
// 14. repeat()
(async () => {
let { input } = require("jsshort");
let strRepeat = await input("Enter a string: ");
let repeatCount = parseInt(await input("Enter number of repetitions: "));
console.log(strRepeat.repeat(repeatCount));
})();
// 15. startsWith()
(async () => {
let { input } = require("jsshort");
let strStartsWith = await input("Enter a string: ");
let searchStringStart = await input("Enter search string: ");
console.log(strStartsWith.startsWith(searchStringStart));
})();
// 16. endsWith()
(async () => {
let { input } = require("jsshort");
let strEndsWith = await input("Enter a string: ");
let searchStringEnd = await input("Enter search string: ");
console.log(strEndsWith.endsWith(searchStringEnd));
})();
// 17. substr()
(async () => {
let { input } = require("jsshort");
let strSubstr = await input("Enter a string: ");
let startSubstr = parseInt(await input("Enter start index: "));
let lengthSubstr = parseInt(await input("Enter length: "));
console.log(strSubstr.substr(startSubstr, lengthSubstr));
})();
// 18. trimStart() - trimLeft() is an alias
(async () => {
let { input } = require("jsshort");
let strTrimStart = await input("Enter a string: ");
console.log(strTrimStart.trimStart());
})();
// 19. trimEnd() - trimRight() is an alias
(async () => {
let { input } = require("jsshort");
let strTrimEnd = await input("Enter a string: ");
console.log(strTrimEnd.trimEnd());
})();
// 20. match()
(async () => {
let { input } = require("jsshort");
let strMatch = await input("Enter a string: ");
let regexPattern = await input("Enter regular expression: ");
console.log(strMatch.match(regexPattern));
})();
String functions in js 👆
Javascript object methods 👇
// 1. Object.keys()
let sampleObject = { name: 'John', age: 30, city: 'New York' };
console.log(Object.keys(sampleObject));
// 2. Object.values()
let sampleObject = { name: 'John', age: 30, city: 'New York' };
console.log(Object.values(sampleObject));
// 3. Object.entries()
let sampleObject = { name: 'John', age: 30, city: 'New York' };
console.log(Object.entries(sampleObject));
// 4. Object.assign()
let obj1 = { a: 1, b: 2 };
let obj2 = { b: 4, c: 5 };
let mergedObject = Object.assign({}, obj1, obj2);
console.log(mergedObject);
// 5. Object.freeze()
let sampleObject = { name: 'John', age: 30 };
Object.freeze(sampleObject);
// Attempting to modify a frozen object will not work
// 6. Object.seal()
let sampleObject = { name: 'John', age: 30 };
Object.seal(sampleObject);
// Attempting to add/delete properties in a sealed object's descriptor will not work
// 7. Object.getOwnPropertyDescriptor()
let sampleObject = { name: 'John', age: 30 };
let descriptor = Object.getOwnPropertyDescriptor(sampleObject, 'age');
console.log(descriptor);
// 8. Object.getOwnPropertyNames()
let sampleObject = { name: 'John', age: 30 };
console.log(Object.getOwnPropertyNames(sampleObject));
// 9. Object.getPrototypeOf()
let sampleObject = {};
console.log(Object.getPrototypeOf(sampleObject));
// 10. Object.hasOwnProperty()
let sampleObject = { name: 'John', age: 30 };
console.log(sampleObject.hasOwnProperty('age'));
// 11. Object.create()
let sampleObject = { name: 'John', age: 30 };
let newObject = Object.create(sampleObject);
console.log(newObject);