1

Hello I'm trying to delete only the keys from an array, I have this

{everyone: "everyone", random: "random", fast response time: "fast response time", less conversations: "less conversations"}

But I need this array in this way

["everyone", "random", "fast response time", "less conversations"]

I need only the values on this array, I have this code but it brings me an empty array

let array = {everyone: "everyone", random: "random", fast response time: "fast response time", less conversations: "less conversations"};
delete translation['everyone'];
delete translation['random'];
delete translation['fast response time'];
delete translation['less conversations'];
console.log(translation);
1
  • 1
    what's "translation"? Commented Jul 7, 2021 at 19:49

1 Answer 1

6

Object.values() will spit out the values in an array. Also your keys with spaces need to be quoted.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values

const test = {
  everyone: "everyone",
  random: "random",
  "fast response time": "fast response time",
  "less conversations": "less conversations"
}

console.log(Object.values(test));

1
  • Yes, that's what I've been looking foor, thank you so much
    – Alexis
    Commented Jul 7, 2021 at 20:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.