

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Replacing array of object property name in JavaScript
Following is the code to replace array of object property name in JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } </style> </head> <body> <h1>Replacing array of object property name</h1> <div class="result"></div> <button class="Btn">CLICK HERE</button> <h3>Click the above button to change the property name of an object in array</h3> <script> let BtnEle = document.querySelector(".Btn"); let resEle = document.querySelector(".result"); var person = [ { name: "Rohan Sharma", age: 16 }, { name: "Vinit Mehta", age: 18 }, ]; person = person.map((item) => { return { fullName: item.name, age: item.age, }; }); BtnEle.addEventListener("click", () => { person.forEach((item) => { resEle.innerHTML += "fullName = " + item.fullName + " : Age = " + item.age + ""; }); }); </script> </body> </html>
Output
The above code will produce the following output −
On clicking the ‘CLICK HERE’ button −
- Related Questions & Answers
- JavaScript: replacing object keys with an array
- JavaScript Adding array name property to JSON object [ES5] and display in Console?
- HTML DOM Object name Property
- Sum of array object property values in new array of objects in JavaScript
- JavaScript Error name Property
- How to Declare an Object with Computed Property Name in JavaScript?
- Replacing Array Elements in Perl
- Convert array of object to array of array in JavaScript
- Add object to array in JavaScript if name does not already exist?
- Array grouping on the basis of children object’s property in JavaScript
- map() array of object titles into a new array based on other property value JavaScript
- Sorting an array object by property having falsy value - JavaScript
- Un-nesting array of object in JavaScript?
- Grouping on the basis of object property JavaScript
- Replacing spaces with underscores in JavaScript?
Advertisements