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
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 −
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
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
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
Following is the code to format JavaScript object to new Array −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } Formatting JavaScript Object to new Array. CLICK HERE Click on the above button to format the school object to an array const school = { name: "St Marks", address: "Delhi", students: ... Read More
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
Following is the code to print last element of an 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; } JavaScript code to print last element of an array. CLICK HERE Click on the above button to get the last element of the above array let resEle = ... Read More
Following is the code to implement short circuit assignment in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 20px; font-weight: 500; color: blueviolet; } .sample { color: red; } Short-circuit assignment a=22 || 0 || 0b=0 && 22 && 22 Click Here Click on the above button to see the values of variable a and b in the ... Read More
Short circuit evaluation basically works with the && and || logical operators. The expressions are evaluated left to right.For && operator − Short circuit evaluation with &&(AND) logical operator means if the first expression evaluates to false then whole expression will be false and the rest of the expressions will not be evaluated.For || operator − Short circuit evaluation with ||(OR) logical operator means if the first expression evaluates to true then the whole expression will be true and the rest of the expressions will not be evaluated.Following is the code for short circuit evaluation in JavaScript −Example Live Demo ... Read More