Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

clear whitespace from object javascript

var obj = {
  "  employee   name": "Sumit Vishwakarma",
  "employee id ": 001,
  "email ": "abc@gmail.com",
  "mobile  no": 9999999999,
};

Object.keys(obj).forEach((key) => {
   var replacedKey = key.trim().toUpperCase().replace(/ss+/g, "_");
   if (key !== replacedKey) {
      obj[replacedKey] = obj[key];
      delete obj[key];
   }
});
console.log(obj);

result
  EMAIL: "abc@gmail.com",
  EMPLOYEE ID: 1,
  EMPLOYEE_NAME: "Sumit Vishwakarma",
  MOBILE_NO: 9999999999
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: JsonConvert.DeserializeObject convert into dynamic datatable 
Javascript :: javascript validate date 
Javascript :: express trust proxy 
Javascript :: should i use google pay 
Javascript :: javascript remove characters from beginning of string 
Javascript :: check if there is page has scrollbar x js 
Javascript :: jquery validation submit handler 
Javascript :: jquery ready 
Javascript :: is_int js 
Javascript :: DataTypes Time sequelize 
Javascript :: javascript pass all arguments to another function 
Javascript :: how to clear local storage 
Javascript :: ng class in angular 
Javascript :: where to place async in const function 
Javascript :: how to create a folder in node js 
Javascript :: refresh after delete in express 
Javascript :: array remove index from array 
Javascript :: check if type is blob javascript 
Javascript :: javascript alert on refresh 
Javascript :: sequelize delete item 
Javascript :: on hover add class on children jquery 
Javascript :: keypress event 
Javascript :: AWS S3 JavaScript example 
Javascript :: discord.js messageDelete 
Javascript :: get all entries in object as array hjs 
Javascript :: how to split a name js 
Javascript :: install react router dom 
Javascript :: “javascript remove last element from array 
Javascript :: javascript date time formating 
Javascript :: how to turn a number negative in javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =