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
Category: JavaScript
Merge two arrays and removes all duplicates elements
JavaScript function that merges two arrays and removes all duplicate elements. Test data:var array1 = [1, 2, 3];var array2 = [2, 30, 1];// console.log(merge_array(array1, array2));// Output: [3, 2, 30, 1]
JavaScript Array Functions
Map, reduce, and filter are all array methods in JavaScript. Each one will iterate over an array and perform a transformation or computation. Each will return a new array based on the result of the function. Map The map() method is used to create a new array from an existing one, applying a function to each… Continue reading JavaScript Array Functions
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
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
Browser storage: Local Storage, Session Storage, Cookie, IndexedDB and WebSQL
Local Storage Key-value storage that stores values as strings Does not have expiration date (persistent storage) unless explicitly clear the browser using settings or Javascript Up to 10MB data can be stored Follow the same-origin policy, which means the Protocol(Http/Https), port and the host are the same. Only scripts of the same origin can access… Continue reading Browser storage: Local Storage, Session Storage, Cookie, IndexedDB and WebSQL
Enum in JS
Enum is a data type in programming languages that defines a set of constant values. It is a distinct value type (i.e.) all values in an enum are unique. Using an enum makes the code readable and maintainable. Some examples of enum are all weekdays from Monday to Sunday, T-shirt sizes like S, M, L, XL, etc. The pseudocode of an enum… Continue reading Enum in JS
Install and use PrimeVue Library in Vue project.
PrimeVue is a rich set of open source UI components for Vue. Run the following command in your command line. Add provided code in main.js To import components of Primevue to use it, add provided code in main.js. Take Button as example. Use the component in Vue file as provided.