Breaking forEach loop in JavaScript

forEach loop in JavaScript cannot be broken by using break statement. Here are some ways to break a forEach loop: Using Array. length: arr=[1,2,3,4,5]; arr.forEach(function(value){    if(value == 2){        arr.length=0;    }    console.log(‘value=’, value);    }); Using splice: arr=[1,2,3,4,5]; arr.forEach(function(value,index){    if(value == 2){        arr.splice(index+1, arr.length);    }… Continue reading Breaking forEach loop in JavaScript

Published
Categorized as JavaScript

‘toReversed’ method in JavaScript

The method ‘toReversed()’ is added to JavaScript in ECMAScript 2023 (ES 13) version. The advantage of this method over ‘reverse()’ is that it doesn’t change the original array. It reverses the array and returns a new array. Below is the example code for it and the output: x=[1,2,3,4,5]; x.reverse(); console.log(‘The reverse method applied and the… Continue reading ‘toReversed’ method in JavaScript

Published
Categorized as JavaScript Tagged

Convert an SVG file to Vue file.

Consider this is an svg file and the code looks like this. Use <template> tag and insert the content inside in it as shown below. Then save the file with .vue extension

Published
Categorized as JavaScript Tagged

Install and use Pinia in Vue.

Pinia is a store library for Vue, it allows you to share a state across components/pages. To install pinia type this in command prompt. After installing pinia, enter the script in main.js file Given is the Javascript sample of pinia

Class basic syntax

Class basic syntax In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods).Wikipedia In practice, we often need to create many objects of the same kind, like users, or goods or whatever. As we already know from the chapter Constructor, operator… Continue reading Class basic syntax

JavaScript Weird Behaviour

✍🏻 Notation // -> is used to show the result of an expression. For example: 1 + 1; // -> 2 // > means the result of console.log or another output. For example: console.log(“hello, world!”); // > hello, world! // is just a comment used for explanations. Example: // Assigning a function to foo constant const foo = function() {};… Continue reading JavaScript Weird Behaviour

Published
Categorized as JavaScript