Found 9297 Articles for Object Oriented Programming

Explain Deep cloning an object in JavaScript with an example.

AmitDiwan
Updated on 18-Jul-2020 08:41:52

125 Views

Following is the code for deep cloning an object in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Deep cloning an object in javascript CLICK HERE Click the above button to deep clone the obj object    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");    let obj = {       firstName: "Rohan",       ... Read More

Using methods of array on array of JavaScript objects?

AmitDiwan
Updated on 18-Jul-2020 08:39:39

142 Views

Following is the code for using methods of array on array of JavaScript objects −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Using methods of array on array of JavaScript objects CLICK HERE Click the above button to apply array methods on array of objects    let BtnEle = document.querySelector(".Btn");    let arr = [       {   ... Read More

How to convert dictionary into list of JavaScript objects?

AmitDiwan
Updated on 18-Jul-2020 08:36:54

1K+ Views

Following is the code to convert dictionary into list of JavaScript objects −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample{       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Convert dictionary into list of JavaScript objects { A: { 1: "Apple", 2: "Apricot" }, B: { 1: "Ball", 2: "Bull" }, C: { 1: "Cat", 2: "Cow" }, D: { 1: "Dog", 2: "Drill" }, } CLICK HERE Click the ... Read More

JavaScript example to filter an array depending on multiple checkbox conditions.

AmitDiwan
Updated on 18-Jul-2020 08:25:51

2K+ Views

Following is the code to filter an array depending on multiple checkbox condition using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .result {       color: red;    } Filter an array depending on multiple checkbox conditions [22, 10, 50, 30, 90, 33, 80, 75, 33, 99, 150, 105] Number should be greater than 50 ... Read More

How to duplicate elements of an array in the same array with JavaScript?

AmitDiwan
Updated on 18-Jul-2020 08:22:41

459 Views

Following is the code to duplicate elements of an array in the same array −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,.sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .result {       color: red;    } Duplicate elements of an array in the same array [1,2,3,4,'A'] CLICK HERE Click on the above button to duplicate the elements of the above array    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let arr = [1, 2, 3, 4, "A"];       BtnEle.addEventListener("click", () => {          arr = arr.concat(arr).sort();          resEle.innerHTML = arr;       }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

How to share private members among common instances in JavaScript?

AmitDiwan
Updated on 18-Jul-2020 08:21:50

90 Views

Following is the code for sharing private members among common instances in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: blueviolet;    } Share private members among common instances in JavaScript Click Here Click on the above button to display the personName property    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    function Person(name) {       let ... Read More

Object.keys().map() VS Array.map() in JavaScript

AmitDiwan
Updated on 18-Jul-2020 08:19:45

721 Views

Following is the code showing Object.keys().map() and Array.map() in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .result {       color: red;    } Object.keys().map() VS Array.map() {1:'A', 22:'B', 55:'C', 19:'D'} CLICK HERE Click on the above button to sum the keys of the above object [22, 33, 11, 44] CLICK HERE Click on the ... Read More

Using closures to achieve privacy in JavaScript

AmitDiwan
Updated on 18-Jul-2020 08:17:58

73 Views

Following is the code for implementing closures to achieve privacy in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: blueviolet;    } Using closures to achieve privacy Increment Access Click on the above button to increment or try to access the variable    let resEle = document.querySelector(".result");    let BtnEle = document.querySelectorAll(".Btn");    function increment() {       let a ... Read More

Can we assign new property to an object using deconstruction in JavaScript?

AmitDiwan
Updated on 18-Jul-2020 08:18:28

78 Views

Following is the code to assign new property to an object using deconstruction in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .result {       color: red;    } Assign new property to an object using deconstruction {"a":11, "b":22, "c":44} CLICK HERE Click on the above button to assign values to obj by destructuring above object ... Read More

JavaScript -Short-circuiting in boolean

AmitDiwan
Updated on 18-Jul-2020 08:12:12

116 Views

Following is the code for short circuiting in boolean −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;       color: blueviolet;    } Short-circuit Boolean && short circuit evaluation || short circuit evaluation Click on the above button to see the the short circuit evaluation    let resEle = document.querySelector(".result");    let BtnEle = document.querySelectorAll(".Btn");    function retTrue() {       resEle.innerHTML += "True ... Read More

Advertisements