Processing of subarray data

Asked

Viewed 21 times

-1

I have an array(thirdArray) and there is a subArray(data). I need to do a treatment, where every data you have with an amount above 0 he receives a status true but a status false.

After doing this treatment, I need to update this main Array(thirdArray) with these status.

I’m doing it the way below, but I’m not sure how to handle the spread correctly.

I hope you can help me.

let originalData = [
      {
        language:'JS',
        data:[
          {
            id:1,
            name:'ReactJS',
            lang:'JS',
            amount:1,
          },
          {
            id:2,
            name:'Angular',
            lang:'JS',
            amount:0
          }
        ]
      },
      {
        language:'PHP',
        data:[
          {
            id:3,
            name:'Laravel',
            lang:'PHP',
            amount:1
          }
        ]
      }
    ];

    const lang = originalData.map((lang)=> lang.data );

    
    //Tratamento de dados com a definição de status
    const values = lang.map((data)=> {
      return data.map((values)=>
        values.amount > 0
        ? {...values,status:true}
        : {...values,status:false}
      )
    })

const newData = originalData.map((item)=>
      item.language === 'JS'
      ? {...item,data:values}
      : item
      )

when I use console.log to print the newData is printing like this: inserir a descrição da imagem aqui

Problem: I wish Laravel didn’t display in the Intel zero array

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.