-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.

0

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.