-2

I have the following object:

let obj = {
  ArticleNumber: "173224",
  StoreNumber: "40",
  DeliveryDate: "1/30/2017",
  Qty: "110",
  UOM: "C03"
}

Now, I want to create an array of only property names, not values. I saw getProperty() method but it is not working. I want something like below:

{"ArticleNumber","StoreNumber","DeliveryDate","Qty","UOM"} in an array.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
AK47
  • 3,707
  • 3
  • 17
  • 36

2 Answers2

2

This should help:

var keyNames = Object.keys(obj);

where the return value is

An array of strings that represent all the enumerable properties of the given object.

You could find more information here.

Rufi
  • 2,529
  • 1
  • 20
  • 41
0

You can do like this by using for loop.

var yourObject = { ArticleNumber: "173224", 
                   StoreNumber: "40", 
                   DeliveryDate: "1/30/2017", 
                   Qty: "110", 
                   UOM: "C03"}

create another array for property names

var propertyNameArr = [];

you can loop through property names in an array like this

for(propertyName in yourObject){
   propertyNameArr.push(propertyName);
}

Now propertyNameArr will have all property name.

Manjunath M
  • 588
  • 1
  • 6
  • 30