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);
Alexis
  • 51
  • 1
  • 8

1 Answers1

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));
Matt
  • 5,315
  • 1
  • 30
  • 57