Hi Friends đź‘‹,

Welcome to Infinitbility ❤️!

Today, I’m going to show you how to convert object values to array in typescript, here we use some javascript Objects method like Object.values() method.

Sometime’s we need to create array from object values and that’s why we simple method Object.values()

interface User {
  id: number;
  name: string;
  domain?: string;
  age?: number;
  isActive?: boolean;
}

let user: User = {
  id: 1,
  name: "infinitbility",
  domain: "infinitbility.com",
  age: 2,
  isActive: 1
};

let userKeys = Object.values(user).map(key => {return key});

When you run above code you will get all your objects property in array, check below output image.

Output

TypeScript, convert object values to array example
TypeScript, convert object values to array example

All the best đź‘Ť.