DEV Community

MOHSIN ALI SOOMRO
MOHSIN ALI SOOMRO

Posted on

2 1

How to get json value in json key

const DATA = [
    {
      id: 1,
      jobname: "asdfa",
      jobdescription: "N/A",
      duration: "01:45:00",
      baseprice: 65,
      jobslots: 21,
      business: 5,
      employee: null,
      discountrates: 1
    },
    {
      id: 2,
      jobname: "sfasdf",
      jobdescription: "N/A",
      duration: "00:45:00",
      baseprice: 65,
      jobslots: 9,
      business: 5,
      employee: null,
      discountrates: 1
    },
    {
      id: 3,
      jobname: "sdfdf",
      jobdescription: "N/A",
      duration: "01:15:00",
      baseprice: 65,
      jobslots: 15,
      business: 5,
      employee: null,
      discountrates: 1
    },
    {
      id: 4,
      jobname: "cfa",
      jobdescription: "N/A",
      duration: "00:45:00",
      baseprice: 65,
      jobslots: 9,
      business: 5,
      employee: null,
      discountrates: 1
    },
    {
      id: 5,
      jobname: "dfs",
      jobdescription: "N/A",
      duration: "01:15:00",
      baseprice: 65,
      jobslots: 15,
      business: 5,
      employee: null,
      discountrates: 1
    },
    {
      id: 6,
      jobname: "fafa",
      jobdescription: "N/A",
      duration: "00:45:00",
      baseprice: 65,
      jobslots: 9,
      business: 5,
      employee: null,
      discountrates: 1
    },
    {
      id: 7,
      jobname: "sfda",
      jobdescription: "N/A",
      duration: "01:00:00",
      baseprice: 65,
      jobslots: 12,
      business: 5,
      employee: null,
      discountrates: 1
    },
    {
      id: 8,
      jobname: "aaa",
      jobdescription: "N/A",
      duration: "00:30:00",
      baseprice: 65,
      jobslots: 6,
      business: 5,
      employee: null,
      discountrates: 1
    },
    {
      id: 9,
      jobname: "ggg",
      jobdescription: "N/A",
      duration: "01:30:00",
      baseprice: 65,
      jobslots: 18,
      business: 5,
      employee: null,
      discountrates: 1
    },
    {
      id: 10,
      jobname: "kjkj",
      jobdescription: "N/A",
      duration: "01:15:00",
      baseprice: 65,
      jobslots: 15,
      business: 5,
      employee: null,
      discountrates: 1
    }
  ];
  let arr = [];
  DATA.map((d, index) => {
    arr.push({ ["job-id " + [d.id]]: { 
      business: d.business ,
      jobslots:d.jobslots,
      jobname:d.jobname
    } });
  });
Enter fullscreen mode Exit fullscreen mode

OUTPUT

[
   {
      "job-id 1":{
         "business":5,
         "jobslots":21,
         "jobname":"asdfa"
      }
   },
   {
      "job-id 2":{
         "business":5,
         "jobslots":9,
         "jobname":"sfasdf"
      }
   },
   {
      "job-id 3":{
         "business":5,
         "jobslots":15,
         "jobname":"sdfdf"
      }
   },
   {
      "job-id 4":{
         "business":5,
         "jobslots":9,
         "jobname":"cfa"
      }
   },
   {
      "job-id 5":{
         "business":5,
         "jobslots":15,
         "jobname":"dfs"
      }
   },
   {
      "job-id 6":{
         "business":5,
         "jobslots":9,
         "jobname":"fafa"
      }
   },
   {
      "job-id 7":{
         "business":5,
         "jobslots":12,
         "jobname":"sfda"
      }
   },
   {
      "job-id 8":{
         "business":5,
         "jobslots":6,
         "jobname":"aaa"
      }
   },
   {
      "job-id 9":{
         "business":5,
         "jobslots":18,
         "jobname":"ggg"
      }
   },
   {
      "job-id 10":{
         "business":5,
         "jobslots":15,
         "jobname":"kjkj"
      }
   }
]

Enter fullscreen mode Exit fullscreen mode

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay