-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
  • 15,517
  • 8
  • 61
  • 146
AK47
  • 3,599
  • 3
  • 16
  • 35

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,359
  • 1
  • 18
  • 37
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
  • 5
  • 29