Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
How to call State from Class component with combined String?

Instead of using the original way like this.state, I want to use the combined String.

import React, { Component } from "react";

class Test extends Component {
  constructor(props) {
    super(props);
    this.state = {
      Monday100: "Monday100",
    };
  }

  render() {
    let day = "Monday";
    let number = "100";
    let dayAndNumber = day + number;

    return (
      <div>
        {/* I Want To Do It Like This */}
        {/* {this.state.dayAndNumber} */}
        {/* Original Way */}
        {this.state.Monday100}
      </div>
    );
  }
}

export default Test;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can accss by this.state[dayAndNumber]

import React, { Component } from "react";

class Test extends Component {
  constructor(props) {
    super(props);
    this.state = {
      Monday100: "Monday100",
    };
  }

  render() {
    let day = "Monday";
    let number = "100";
    let dayAndNumber = day + number;

    return (
      <div>
        {/* I Want To Do It Like This */}
        {/* {this.state.dayAndNumber} */}
        {/* Original Way */}
        {this.state[dayAndNumber]}
      </div>
    );
  }
}

export default Test;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!