Web Development Articles

Page 73 of 801

How to create a unique ID for each object in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

Following is the code to create a unique ID for each object −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Create a unique ID for each object CLICK HERE {       if (obj.id === obj1.id) {          resEle.innerHTML = "The id generated are not unique ";       }       else {          resEle.innerHTML = "The id generated is unique for each object";       }    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Read More

How to access an object through another object in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 516 Views

Following is the code to access an object through another object in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Access an object through another object in JavaScript CLICK HERE Click on the above button to display obj2    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let obj = {       firstName: "Rohan",     ...

Read More

How to create a multidimensional JavaScript object?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 4K+ Views

Following is the code to create a multidimensional JavaScript object −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple; } Create a multidimensional JavaScript object CLICK HERE Click on the above button to create and display a multidimensional object    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    BtnEle.addEventListener("click", () => {       let obj = {          firstName: "Rohan",          lastName: "Sharma",          school: {             name: "St Marks",             address: {                city: "Dwarka",                state: "Delhi",             },          },       };       console.log(obj);    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button and inspecting the output in console −

Read More

How to assign values to an array with null/empty objects in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 958 Views

Following is the code to assign values to an array with null/empty objects using JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Assign values to an array with null/empty objects CLICK HERE Click on the above button to assign values to empty object inside arrObj    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let obj = { ...

Read More

Can we convert two arrays into one JavaScript object?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 242 Views

Following is the code to convert two arrays into one JavaScript object −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .result {       color: red;    } Convert two arrays into one JavaScript object ["firstName", "lastName", "age"]["Rohan", "Sharma", 21] CLICK HERE Click on the above button to create an object from the above two arrays ...

Read More

The image() object in JavaScript.

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 3K+ Views

The image object represents the HTML  element.Following is the code for image object in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } The image() object in JavaScript CLICK HERE Click on the above button to display an image    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let newImage = new Image(500, 300);    newImage.src = "https://i.picsum.photos/id/195/536/354.jpg";    BtnEle.addEventListener("click", () => {       resEle.appendChild(newImage);    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Read More

Explain JavaScript text alert

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 245 Views

The JavaScript alert() function is used to display a popup message to the user.Following is the code for the JavaScript alert() function −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    } Javascript text alert CLICK HERE Click on the above button to trigger the alert popup    let BtnEle = document.querySelector(".Btn");    BtnEle.addEventListener("click", () => {       alert("You pressed the button");    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Read More

How to merge objects into a single object array with JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 320 Views

Following is the code to merge objects into a single object array −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .sample {       color: red;    } Merge objects into a single object array [{id:22, class:7}, {name:'Rohan', age:12}, {state:'Delhi', country:'India'}] CLICK HERE Click on the above button to merge the above objects inside array into a ...

Read More

Is there an elegant way of passing an object of parameters into a function?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 111 Views

Following is the code to pass an object of parameters to a function −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .sample {       color: red;    } Passing an object of parameters into a function CLICK HERE Click on the above button to add 4 object values by passing them to a function    let resEle ...

Read More

Is it possible to de-structure to already-declared variables? In JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 176 Views

Following is the code to de-structure already declared variables in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } De-structure to already-declared variables CLICK HERE Click on the above button to destructure the personObj object    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let name, age, personObj;    personObj = {       name: "Rohan",       age: 19,    };    BtnEle.addEventListener("click", () => {       ({ name, age } = personObj);       resEle.innerHTML = " name = " + name + "age = " + age;    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Read More
Showing 721–730 of 8,006 articles
« Prev 1 71 72 73 74 75 801 Next »
Advertisements