
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to modify key values in an object with JavaScript and remove the underscore?
In order to modify the key values, you need to use regular expressions along with Object.fromEntries().
Example
var underscoreSpecifyFormat = str => str.replace(/(_)(.)/g, (_, __, v) => v.toUpperCase()), JsonObject = { first_Name_Field: 'John', last_Name_Field: 'Smith'}, output = Object.fromEntries(Object.entries(JsonObject).map(([key, value]) => [underscoreSpecifyFormat(key), value])); console.log("The JSON Object="); console.log(output);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo89.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo89.js The JSON Object= { firstNameField: 'John', lastNameField: 'Smith' }
- Related Articles
- Retrieve key and values from object in an array JavaScript
- How to return object from an array with highest key values along with name - JavaScript?
- JavaScript: How to remove the key-value pairs corresponding to the given keys from an object?
- Update a column in MySQL and remove the trailing underscore values
- How to modify an array value of a JSON object in JavaScript?
- How to remove everything before values starting after underscore from column values of an R data frame?
- Iterate through Object keys and manipulate the key values in JavaScript
- How to get key name when the value contains empty in an object with JavaScript?
- How to remove an object using filter() in JavaScript?
- How to modify properties of a nested object in JavaScript?
- How to get the values of an object in JavaScript?
- How to access an object having spaces in the object’s key using JavaScript?
- How to access an object value using variable key in JavaScript?
- How to merge an array with an object where values are arrays - JavaScript
- How to remove falsy values from an array in JavaScript?

Advertisements