define instance variables with identical values

Within my object, there exist multiple properties where the values are identical while the keys vary

const arr: any = {
        Combo: ['state', 'command'],
       Extrahit: ['state', 'command'],
        Punish: ['frame', 'command', 'damage', 'range', 'hitframe'],
        standing: ['frame', 'command', 'damage', 'range', 'hitframe'],
        up: ['frame', 'command', 'damage', 'range', 'hitframe'],

    };

I am seeking ways to simplify this declaration section.

One suggestion I came across was utilizing iteration functions, but that does not seem applicable to my specific scenario.

I am interested in enhancing the readability of the code. Any suggestions on how I can achieve this?

Answer №1

One way to improve code readability and efficiency is by creating reusable variables:

const stateVariables = ['state', 'command']
const frameValues = ['frame', 'command', 'damage', 'range', 'hitframe'] 

const data: any = {
        Combo: stateVariables,
        Extrahit: stateVariables,
        Punish: frameValues,
        standing: frameValues,
        up: frameValues,
    };

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

Tips for turning off dates on a calendar using JavaScript

Here is the code snippet I'm working with: $(".datepicker").datepicker(); $(".datepicker-to").datepicker({ changeMonth: true, changeYear: true, maxDate: "0D" }); Next, let's take a look at my input fields: <div> <span& ...

Issue with ng-annotate when using Babel and object destructuring

Encountering a peculiar issue while transpiling to ES6 using Babel, where ng-annotate seems to have an aversion to destructuring. I decided to test my code in the online Babel compiler and it worked without any errors. Interestingly, disabling ng-annotate ...

Creating a Selection Menu with JavaScript, HTML, and jQuery

I am currently working on a JavaScript function that will display a dropdown list based on the day of the week. However, I seem to be facing some issues with my code and I cannot pinpoint where the syntax error lies. HTML: <html> <head>< ...

Move a div by dragging and dropping it into another div

Situation Within my project, there is a feature that involves adding a note to a section and then being able to move it to other sections, essentially tracking tasks. I have successfully implemented the functionality to dynamically add and drag notes with ...

Retrieving data from a directive in an HTML table

Utilizing AngularJS, I am seeking a method to retrieve the value from an input located within a specific row in a table. Presented below is an input element. Upon clicking the "add" button, my objective is to extract the value corresponding to that partic ...

Is there a way to track dynamic changes in window dimensions within Vue?

Working on my Vue mobile web app, I encountered an issue with hiding the footer when the soft keyboard appears. I've created a function to determine the window height-to-width ratio... showFooter(){ return h / w > 1.2 || h > 560; } ...and ...

Is it possible to use an image loaded as a texture to create another texture mipmap in three.js?

This is not a problem, it's simply a question. Currently, I am working on a terrain project using an atlas texture. In order to reduce color bleeding, I am planning to create mipmaps externally and then apply them to the terrain texture. At the mome ...

Storing external div content in a variable

On my webpage, I display the status of my webservice task in the following format: <body> <div id="size"> <c:out value="${size}"/> </div> <div id="isRunning"> <c:out value="${isRunning}"/> ...

You are unable to use multiple background colors on a material UI snackbar

Is there a way to apply multiple background colors to a material UI snackbar? I attempted using linear-gradient as shown below, but it didn't work. import Snackbar from 'material-ui/Snackbar'; const bodyStyle = { border: `2px solid ${co ...

Ways to separate a multi-dimensional array of strings

How can we extract data from a string in an array? The array contains multi-dimensional variables. Example Input String CONTAINER [1, "one", false, [CONTAINER [2, "two", false]], 42, true] Expected Output CONTAINER 1 "one" false [CONTAINER [2, "two", ...

Issue on WordPress where JQuery is undefined causing continuous refreshing on IPhone devices

My wordpress website is performing well in most browsers, including some mobile ones. However, when accessed on an IPhone, the homepage keeps refreshing in a continuous loop. Even after emulating an IPhone using Chrome developer tools, the issue persists. ...

Retrieving integers from a text file and manipulating them within an array list using Java

Within my text file, the following statements are present: " I have 3 apples and 1 banana. All people have 4 cars at least." My objective is to extract integers from this .txt file and store them in an ArrayList. public class ...

How can I use D3.js to form a circular group in an organization structure, link it with a circular image, and connect

Is it possible to create a radial grouped circle using d3.js, similar to the image below: https://i.sstatic.net/1Hwd2.jpg I have written some code as shown below. However, I am facing challenges in connecting every circle with a curved line and displayi ...

Set the position of a div element to be fixed

I am currently working on a straightforward application that requires implementing a parallax effect. Here are the methods I have experimented with so far: - Inserting an image within a div with the class parallax. - Subsequently, adding an overlay div ...

Sending a notification alert directly to the client's web browser

My goal is to develop an application that allows Super users to notify other users by providing access to content, such as a PDF file, when they click on a link. For example, in the scenario where a teacher wants to share a PDF with students, this applica ...

What could be causing the Firebase email verification to result in a 400 error?

I've been struggling to implement email verification in my React website. Every time I try to use the sendSignInLinkToEmail function, I keep encountering this error: XHRPOSThttps://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=XXXXXXXXXXX ...

ASP.NET Core - Populating views with data gradually

I'm currently working on a .Net Core application and I have reached a point in my code where I need to dynamically add data based on user interactions. Initially, I have a table displaying elements, and when a user clicks on any element, I need to ret ...

Tips for seamlessly integrating XHP and ReactJS for a component's implementation

Imagine this scenario: a blog with a posts feed. Upon loading the page, three <PostCard>s are already loaded from the server-side. As the user scrolls down or clicks a Load more button, new post cards should be dynamically added to the page. We have ...

What methods can be used to construct components using smaller foundational components as a base?

Is there a more elegant approach to constructing larger components from smaller base components that encompass common functionalities, akin to an interface in the OOP realm? I'm experimenting with this concept, but it feels somewhat inelegant. Repor ...

Firebase causing API to render only upon typing initiation

I have been working on developing a Twitter-like app using React and Firebase, but I have come across a small bug. Currently, I am using useEffect to display my firebase collection when the page loads, and then mapping the tweets to the page. However, the ...