How to Uppercase the Keys of Each Object Element in Vue.js

I've got this particular item:

{
'application': "BP 9ALT 8 123",
 'address': "935 HAMPTON CRES",
 'unit': null,
 'status': "COMPLETED -ALL INSP SIGNED OFF"
}

I'm looking to turn each key into uppercase like so:

{
 'Application': "BP 9ALT 8 123",
 'Address': "935 HAMPTON CRES",
 'Unit': null,
 'Status': "COMPLETED - ALL INSP SIGNED OFF"
}

Any suggestions on how to achieve this easily in Vuejs?

Answer №1

Give this method a try

const data = {
  product: "Apple Watch Series 6",
  color: "Midnight Blue",
  size: "42mm",
  price: "$399",
};

const result = Object.entries(data).map(([key, value]) => [
  key[0].toUpperCase() + key.slice(1),
  value,
]);

console.log(Object.fromEntries(result));

Browse through

Answer №2

Implement a solution using Array.reduce() and String.toUpperCase() as shown below

var data = {
 'name': "John Doe",
 'age': 30,
 'city': "New York"
}

var modifiedDataOne = Object.entries(data).reduce(function(acc, value) {
  acc[value[0].charAt(0).toUpperCase() + value[0].slice(1)] = value[1];
  return acc;
}, {});

// Updated

// Adjusted the reduce function to directly destructure key and value instead of using indexing
var modifiedDataTwo = Object.entries(data).reduce(function(acc, [key, value]) {
  acc[key[0].toUpperCase() + key.slice(1)] = value;
  return acc;
}, {});



console.log(modifiedDataOne);
console.log(modifiedDataTwo);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The dimensions of the HTML table do not adjust properly when new items are being appended using JavaScript

I utilized this HTML Code to generate a table: <div class="noten_tabelle"> <table id="grades_table" style="width:100%"> <tr> <th>Subject</th> <th>Oral</th&g ...

jQuery-powered web application, experiencing compatibility issues when deployed on Windows Server 2003 and Internet Explorer

While developing a web application on XP and FF (with occasional IE checks through IE 8), I encountered an issue when deploying it to a WS 2003 site running IE 7. My jQuery code for dynamically sizing divs does not execute, even when explicitly stating div ...

Validate if cookie has been established in Javascript

Hello everyone! I am trying to redirect a user to another page when a cookie is set by clicking a button. <a href="" onClick="SetCookie('pecCookie','this is a cookie','-1')"><button type="button" name="accept" clas ...

Is there a way to compare timestamps in PostgreSQL using moment.js and focus only on the date aspect?

I've encountered a small issue that has me stumped - I'm trying to figure out the best solution for it. The problem lies in a table I have, with attributes named "Start" and "End". My objective is to store every row in an array where the "Start" ...

Convert JavaBeans sources into a JSON descriptor

I'm in search of a tool or method to analyze standard JavaBeans source code (featuring getters and setters) and create json descriptors using tools like grunt or ant, or any other suitable option. Here's an example: FilterBean.java: package com ...

"Applying a background style to a button upon clicking, without any hover effects, in Vue

Clarification There is an icon within a button that, when clicked, triggers the opening of a menu. To ensure the menu is positioned correctly under the button, I have had to adjust the height. However, this adjustment has resulted in a background hover ef ...

There seems to be a glitch with jQuery on my Angular.js website

I'm trying to implement Masonry.js on my website, and although I've managed to make it work, the solution feels like a messy workaround and I can't quite figure out why it's functioning (and not functioning well). The primary issues I& ...

Transforming the navigation menu using CSS, HTML, and jQuery

One challenge I am facing involves creating a menu similar to the one on http://edition.cnn.com/. I want the clicked button in the menu to receive focus, while the others lose it. Despite trying various methods, I have not been successful. Can someone off ...

Exciting jQuery animations and transitions

Is there a way in JavaScript to call function or method names using a string? For example, when writing jQuery code that applies an effect to specific targets, can the effect be dynamic and changeable by the user? I'm hoping for something like jQuer ...

How can I utilize a custom function to modify CSS properties in styled-components?

I am working with styled components and need to set the transform property based on certain conditions: If condition 1 is true, set the value to x. If condition 2 is true, set the value to y. If neither condition is true, set the value to null. Despite ...

"Trouble with socket.io: events failing to dispatch to other users within the

Currently, I am investigating the behavior of a basic socket.io application. To test this, I have two tabs representing different users, and I am checking if one user receives events triggered by the other. Surprisingly, neither frontend receives the event ...

Unlocking the power of namespaced Vuex getters in Mocha unit testing

I have been working on developing a new Vue component that utilizes a namespaced Vuex getter to retrieve a list of column names. The actual component is functioning properly and runs without any issues. During the Mocha unit testing phase, I set up a mock ...

Scan across a lineup of pictures

I am looking to showcase a series of images in a horizontal alignment, but I want to avoid overloading the screen width. My goal is to allow users to navigate through the images using their mouse - when they move right within the image container, I want t ...

What is causing my JavaScript not to load properly within Bootstrap tabs?

I am facing an issue with my website which has Bootstrap 4 tabs implemented in a blade template. The problem arises when there are tabs within tabs, and upon clicking one tab, the slicks Javascript plugin that I created does not load on other tabs. It on ...

Emerald: Fresh alert for numerous attributes

After updating jade to the latest version, I started seeing a message in the console that says: You should not have jade tags with multiple attributes This change was mentioned as a feature here 0.33.0 / 2013-07-12 Hugely more powerful error reporting ...

Choosing the perfect item with the help of a material's GridList

I've developed a react-mobx application using Material-UI, and the code structure is similar to this: render() { // defining some constants return ( <div> <img src={selectedPhoto} alt={'image title'} /> < ...

What is the best way to incorporate an input id value (based on iteration) into a while loop that points to a specific piece of html located outside of the loop

In my scenario, I need to dynamically add input fields to a form based on the selection made in a dropdown. The issue arises when these new input fields end up sharing the same ID, which is causing problems in the code. To resolve this, I am looking to app ...

Passing a function as a prop within a loop in ReactJs: Here's how to

Looking for assistance on how to send a function in a loop without encountering errors. Is there a way to successfully send a function in a loop and then call it from the function? In CommentListItem.js, I am calling SubCommentListItem. <SubCommentLis ...

I'm struggling to get this carousel working properly. It appears on the screen, but the navigation arrows are unresponsive. How can I fix

How do I transform this into a fully functioning carousel that displays 3 or more cards with each spin of the Carousel? Here's a code snippet I've created, but I'm struggling to show multiple cards on different spins. My objective is to have ...

Executing a Ruby function via AJAX

I am fairly new to working with ajax, and I find myself in need of using it for my Rails application. Here is the function in my controller: def check_code input = params[:input] code = params[:code] if input == code return true else retur ...