javascript only allow show first few characters from a string

javascript only allow show first few characters from a string

var string = ‘Hey, I am good’; string.substring(0,3); // show first 3 characters //result “Hey” Here is what the above code is Doing: 1. We create a variable called string and assign it a value of ‘Hey, I am good’. 2. We call the substring method on the string variable. 3. We pass in two…

settimeout node js

settimeout node js

setInterval(function () { console.log(“Every 5 secondes”); }, 5000); console.log(“now”); Here is what the above code is Doing: 1. We’re creating a function that will be called every 5 seconds. 2. We’re passing that function to setInterval. 3. setInterval will call the function every 5 seconds. 4. The function will print “Every 5 seconds” to the…

require() of ES modules is not supported when importing node-fetch

require() of ES modules is not supported when importing node-fetch

// node-fetch v3 recently stopped support for the // require way of importing it in favor of ES Modules. // Old: const fetch = require(‘node-fetch’); // New: import fetch from “node-fetch”; Here is what the above code is Doing: 1. Importing the node-fetch package. 2. Creating a variable called fetch that is equal to the…

an image gallery is a set of images with corresponding remove buttons

an image gallery is a set of images with corresponding remove buttons

function setup() { var els = document.getElementsByClassName(“remove”); for (var i = 0; i < els.length; i++) { els[i].addEventListener('click', function (e) { e.preventDefault(); e.target.closest('div.image').remove(); }); } } setup(); Here is what the above code is Doing: 1. We're adding a click event listener to all elements with the class "remove". 2. When the user clicks on...

new blob javascript

new blob javascript

//The Blob() constructor returns a new Blob object. The content of the blob //consists of the concatenation of the values given in the parameter array. const obj = {hello: ‘world’}; const blob = new Blob([JSON.stringify(obj, null, 2)], {type : ‘application/json’}); Here is what the above code is Doing: 1. We create a new object called…

bootstrap multiselect change value

bootstrap multiselect change value

// select an option $(‘#demo’).multiselect(‘select’, value); // deselect an option $(‘#demo’).multiselect(‘deselect’, value); // select all options $(‘#demo’).multiselect(‘selectAll’, justVisible); // deselect all options $(‘#demo’).multiselect(‘deselectAll’, justVisible); Here is what the above code is Doing: 1. The first line is initializing the multiselect plugin. 2. The second line is selecting an option. 3. The third line is deselecting…

adding a prototype on vue using nuxt

adding a prototype on vue using nuxt

// create in plugins/hello export default ({ app }, inject) => { // Inject $hello(msg) in Vue, context and store. inject(‘hello’, msg => console.log(`Hello ${msg}!`)) } // add in nuxt.config.js export default { plugins: [‘~/plugins/hello.js’] } Here is what the above code is Doing: 1. The plugin is created in plugins/hello.js. 2. The plugin is…