'How can disable only specific items in an array using their ID's?

if(event. value = "Network") {
  var opt = this. state. exportcontent
  for(conditions to be written)
  {
    condition to be written .disable= true;
  }
}

Here Network is the option that I selected through the event. export content is an array that consists of six items. I only want 1,4 and 6 id's and their values to be enabled for Network. How can I write the condition using for loop in react?

And the rest of the options should get all the 6 ids and values from export content.

I am new to React so I am expecting the values to be shown on my page.



Solution 1:[1]

    var arr =  [
             {
             "customerId": 0,
             "name":"JIO",
             "isDisable": false
            },
            {
            "customerId": 1,
            "name":"ABC",
            "isDisable": false
            },
            {
            "customerId": 2,
             "name":"PQR",
            "isDisable": false
            },
            {
           "customerId": 3,
           "name":"XYZ",
           "isDisable": false
           },
          {
           "customerId": 4,
           "name":"TYE",
           "isDisable": false
           },
           {
           "customerId": 5,
           "name":"PEI",
           "isDisable": false
           },
          ];
       
   const ids = [0,3,5]; 
   const result = arr.map((obj) => {
        if(ids.includes(obj.customerId)){
          obj.isDisable = true;
      }
      return obj;
    })
    
    
console.log(result);

var arr =  [
        {
        "customerId": 1,
        "name":"ABC",
        "isDisable": false
        },
        {
        "customerId": 2,
         "name":"PQR",
        "isDisable": false
        }
      ]
   
   
arr = arr.map((obj) => {
 if(obj.customerId === 1) {
   obj.isDisable = true;
 } 
 return obj;
})

console.log(arr);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1