DEV Community

MOHSIN ALI SOOMRO
MOHSIN ALI SOOMRO

Posted on

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

Top comments (0)