Home > Net >  How to print object value using key as another string
How to print object value using key as another string

Time:04-20

I'm trying to print an objects value by not its own key but a string similar to the key. I somehow got the key match using filter function from the useParams() string, just one more step remaining for my desired output.

import React from 'react';
import { useParams } from 'react-router-dom';

function MoreArticle() {
  const feed = {
    Fall : 'This is the Detailed description about season of Fall',
    Summer : 'This is the Detailed description about season Summer',
    Winter : 'This is the Detailed description about season Winter',
    Monsoon : 'This is the Detailed description about season Monsoon',
    Spring : 'This is the Detailed description about season Spring',
  };

  const { name } = useParams(); //Summer
  const seasons = Object.keys(feed);

  return (
    <div>
      <div>
        {seasons.filter(season => {
          console.log(feed.season);
          return(
            season == name && <div>{season}</div> //Returns Summer
            //season == name && <div>{feed.season}</div> 
            //How to return object description             
  • Related