JavaScript Javascript Object to array then remove element javascript object array find,javascript object array sort,javascript object

I have this object

Object {
  "87291": "valid",
  "1873681927": "valid",
  "nwq89j8jw0qj9": "valid",
  "oVFYfWIUOsONE6JyMGYAbnsPMAr1": "valid",
}

what i want to do is remove object based on key value and return as array.

i used this code :

    let attay = {
      "87291": "valid",
      "1873681927": "valid",
      "nwq89j8jw0qj9": "valid",
      "oVFYfWIUOsONE6JyMGYAbnsPMAr1": "valid",
    }


    let aar = Object.entries(attay)
    attay = Object.keys(attay)

    for(var i = 0; i < attay.length; i++) {
      if(attay[i] == 'oVFYfWIUOsONE6JyMGYAbnsPMAr1'){
        console.log("found "+attay[i]+" at "+i)
        aar.splice(i, 1);
        console.log(aar)
      }else{
        console.log("NOT found at "+i)        
      }
    }

this code worked okay but the output after remove element is like this

Array [
  Array [
    "87291",
    "valid",
  ],
  Array [
    "1873681927",
    "valid",
  ],
  Array [
    "nwq89j8jw0qj9",
    "valid",
  ],
]

expected output should be like

Array [
      "87291": "valid",
      "1873681927": "valid",
      "nwq89j8jw0qj9": "valid",
    ]
Answer:1

Maybe I'm misunderstanding but it seems like you're over-complicating this. You want to remove the property from the object?

let arr = {
  "87291": "valid",
  "1873681927": "valid",
  "nwq89j8jw0qj9": "valid",
  "oVFYfWIUOsONE6JyMGYAbnsPMAr1": "valid",
}

let removeKey = "oVFYfWIUOsONE6JyMGYAbnsPMAr1"
delete arr[removeKey]; // Remove the property

console.log(arr);
Answer:2

If your runtime is okay with the relatively modern entries (and fromEntries), then you can get what you want simply. (Guessing that you're really aiming for an object output, not an array based on the syntax in your question).

let attay = {
  "87291": "valid",
  "1873681927": "valid",
  "nwq89j8jw0qj9": "valid",
  "oVFYfWIUOsONE6JyMGYAbnsPMAr1": "valid",
}

let removeKey = "oVFYfWIUOsONE6JyMGYAbnsPMAr1"

let pairs = Object.entries(attay).filter(e => e[0] != removeKey)
const obj = Object.fromEntries(pairs);
console.log(obj)
Answer:3

You can avoid the less supported fromEntries by using a simple reduce.

let attay = {
  "87291": "valid",
  "1873681927": "valid",
  "nwq89j8jw0qj9": "valid",
  "oVFYfWIUOsONE6JyMGYAbnsPMAr1": "valid",
};
const remove = "oVFYfWIUOsONE6JyMGYAbnsPMAr1";
const res = Object.entries(attay).reduce((acc, [k, v]) => k == remove ? acc : (acc[k] = v, acc), {});
console.log(res);
Answer:4

Is there an efficient way to toggle the Boolean value of multiple variables at once? My variables are lines that I want to show/hide depending on userValue. myList = [lineA, lineB, lineC, lineD] My ...

Is there an efficient way to toggle the Boolean value of multiple variables at once? My variables are lines that I want to show/hide depending on userValue. myList = [lineA, lineB, lineC, lineD] My ...

I am using Webshim to standardise datepickers cross-browser. That's great, but unfortunately it also replaces other form elements, which I am not interested in. Is there a way I can limit webshim/...

I am using Webshim to standardise datepickers cross-browser. That's great, but unfortunately it also replaces other form elements, which I am not interested in. Is there a way I can limit webshim/...

I am building a REST API in NodeJS. I am building the server-side pagination, sorting and filtering. I have a simple implementation of the filter method. This works if the item does not contain any ...

I am building a REST API in NodeJS. I am building the server-side pagination, sorting and filtering. I have a simple implementation of the filter method. This works if the item does not contain any ...

  1. javascript filter array of objects
  2. javascript filter array of objects by value
  3. javascript filter array of objects by key value
  4. javascript filter array by value
  5. javascript filter array by another array
  6. javascript filter array based on another array
  7. javascript filter array of objects by property
  8. javascript filter array by index
  9. javascript filter array of arrays
  10. javascript filter array of strings
  11. javascript filter array example
  12. javascript filter array multiple conditions
  13. javascript filter array unique
  14. javascript filter array into two arrays
  15. javascript filter array of objects by another array
  16. javascript filter array duplicates
  17. javascript filter array of objects unique
  18. javascript filter array of objects by multiple values
  19. javascript filter array by multiple values
  20. javascript filter array of objects by date

I'm trying to break a foreach if a bool variable is valorized: $.each(GlobalVariables.availableServices, function(index, service) { if(state == true){ break; } for (var k = 0; k &...

I'm trying to break a foreach if a bool variable is valorized: $.each(GlobalVariables.availableServices, function(index, service) { if(state == true){ break; } for (var k = 0; k &...

  1. illegal break statement javascript
  2. illegal break statement foreach
  3. illegal break statement nodejs
  4. illegal break statement javascript foreach
  5. illegal break statement jquery
  6. illegal break statement foreach js
  7. illegal break statement c++
  8. illegal break statement switch
  9. illegal break statement protractor
  10. illegal break statement in node js
  11. illegal break statement angularjs
  12. illegal break statement angular.foreach