Skip to main content

Posts

Showing posts from 2022

How to merge Objects in Javascript

 let person = {     firstName: 'Rocky',     lastName: 'g',     age: 23 }; let job = {     jobTitle: 'Angular Developer',     location: 'UK' }; let employee = {     ...person,     ...job }; console.log(employee);

Javascript insert element into Array with specified position

Here inserting the element after shruthi var arr = []; arr[ 0 ] = "uday" ; arr[ 1 ] = "shruthi" ; arr[ 2 ] = "Riyansh" ; arr[ 3 ] = "Rithika" ; arr[ 4 ] = "Tagore" ; console . log (arr. join ()); // uday,shruthi,Riyansh,Rithika,Tagore arr. splice ( 2 , 0 , "Rocky" ); console . log (arr. join ()); // uday,shruthi,Rocky,Riyansh,Rithika,Tagore

Chicken Balls | చికెన్ ముట్టిలు

how to make fish curry

క్యారెట్ ఊరగాయ | carrot pickle

దోసకాయ పూర్ణం | cucumber curry

bottle gourd shale Pickle

javascript filter Array of objects

Description: filtering the array with the conditions return into the new Array Ex: var obj = { 'homes' : [{ "home_id" : "1" , "price" : "120" , "sqft" : "100" , "beds" : "3" , "baths" : "2.0" , }, { "home_id" : "2" , "price" : "1425" , "s qft" : "100" , "beds" : "2" , "baths" : "2.0" , } ] }; var newArray = obj. homes . filter ( function ( el ) { return el. price <= 1000 && el. sqft >= 500 && el. num_of_beds >= 2 && el. num_of_baths >= 2 }); console . log (newArray); Output [ { "home_id" : "1" , "price"

javascript hoisting

Javascript hoisting: In JavaScript, Hoisting is the default behavior of moving all the declarations at the top of the scope before code execution. Basically, it gives us an advantage that no matter where functions and variables are declared, they are moved to the top of their scope regardless of whether their scope is global or local We can call as all the declaration variable going to top while executing the application. Above image assigning x=1 and it is not declared, after creating the alert then declaring the variable. Here it is not throwing any error while executing javascript declarations are going to top. Here var x: is going to top then assigning x=1: Code snippet: // program to display value var a = 6; function greet() { b = 'hi'; console.log(b); // hi var b; } greet(); // hi console.log(b); Output : Hi Uncaught ReferenceError: b is not defined

Javascript Web worker

Web worker is a powerful concept in javascript, which is used to improving performance of applications and it is running as Asynchronously. A web worker is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page . Usages for real-time: If you are doing the complex operation in DOM, sometimes you feel like browser freezing or non functional. Such case you can use Web workers Coding: <!DOCTYPE html> <html> <body> <p>Count numbers: <output id="result"></output></p> <button onclick="startWorker()">Start Worker</button> <button onclick="stopWorker()">Stop Worker</button> <p><strong>Note:</strong> Internet Explorer 9 and earlier versions do not support Web Workers.</p> <script> var w; function startWorker() { if(typeof(Worker) !== "undefined") { if(typeof(w) == "undefined&

global functions in Javascript

var SomeName = function() {      var function1 = function (number) {       return number+1;      }  var anotherFunction = function (number) {      return number+2;       }  return {  function1: function (number) {     return function1(number);      },  function2: function (number) {    return anotherFunction(number);     }   }  }(); ............... Console.log(SomeName.function1(1)); //logs 2 console.log(SomeName.function2(1)); //logs 3

Javascript Array map methods

 The map() method is used to get a modified version of the array or a reduced value using callback functions. map() applies a function to each array element and creates a new array of the returned values Example :1  const listArray = [1,2,3,4,5] const listArray = listArray.map(Item => {     return item * 2; }) console.log(listArray); Output  : [2,4,6,8,10]