how to get json object titles
I'm a new programmer , I know how to use dictionary/JSON to get the value of whatever you want like for example var x = {"name":jack,"age":20};
then x.name = jack
but what if I've a table that has been imported through an unknown EXCEL file and I just want to know the title of each column , how can i do that ?
for example
Var table = [{"id":0 , "name":jack,"age":25,"profession":student},{"id":1 , "name":nora,"age":22,"profession":student}]
i want to make a javascript function that can inform me with titles of each columns , the number of the columns
how can i do that ?
javascript arrays json list
add a comment |
I'm a new programmer , I know how to use dictionary/JSON to get the value of whatever you want like for example var x = {"name":jack,"age":20};
then x.name = jack
but what if I've a table that has been imported through an unknown EXCEL file and I just want to know the title of each column , how can i do that ?
for example
Var table = [{"id":0 , "name":jack,"age":25,"profession":student},{"id":1 , "name":nora,"age":22,"profession":student}]
i want to make a javascript function that can inform me with titles of each columns , the number of the columns
how can i do that ?
javascript arrays json list
do noteVar table =is invalid syntax, and bothname:jack,andprofession:student}is likely wrong too, strings must be enclosed in delimiters
– CertainPerformance
Nov 25 '18 at 23:37
shouldprofession:studentbeprofession:"student"?
– Dacre Denny
Nov 25 '18 at 23:40
i fixed it thanks , correct me if iam not wrong but"profession":studentis the right syntax
– za002
Nov 25 '18 at 23:42
Unlessstudentis a variable, you are wrong :D Also, note that JavaScript, like most of the popular programming languages, is case-sensitive, andVaris notvar. This is correct:var table = [{"id":0 , "name":"jack","age":25,"profession":"student"},{"id":1 , "name":"nora","age":22,"profession":"student"}]
– Amadan
Nov 25 '18 at 23:53
You can validate a json online here : jsonlint.com
– Shim-Sao
Nov 26 '18 at 0:39
add a comment |
I'm a new programmer , I know how to use dictionary/JSON to get the value of whatever you want like for example var x = {"name":jack,"age":20};
then x.name = jack
but what if I've a table that has been imported through an unknown EXCEL file and I just want to know the title of each column , how can i do that ?
for example
Var table = [{"id":0 , "name":jack,"age":25,"profession":student},{"id":1 , "name":nora,"age":22,"profession":student}]
i want to make a javascript function that can inform me with titles of each columns , the number of the columns
how can i do that ?
javascript arrays json list
I'm a new programmer , I know how to use dictionary/JSON to get the value of whatever you want like for example var x = {"name":jack,"age":20};
then x.name = jack
but what if I've a table that has been imported through an unknown EXCEL file and I just want to know the title of each column , how can i do that ?
for example
Var table = [{"id":0 , "name":jack,"age":25,"profession":student},{"id":1 , "name":nora,"age":22,"profession":student}]
i want to make a javascript function that can inform me with titles of each columns , the number of the columns
how can i do that ?
javascript arrays json list
javascript arrays json list
edited Nov 25 '18 at 23:41
za002
asked Nov 25 '18 at 23:36
za002za002
154
154
do noteVar table =is invalid syntax, and bothname:jack,andprofession:student}is likely wrong too, strings must be enclosed in delimiters
– CertainPerformance
Nov 25 '18 at 23:37
shouldprofession:studentbeprofession:"student"?
– Dacre Denny
Nov 25 '18 at 23:40
i fixed it thanks , correct me if iam not wrong but"profession":studentis the right syntax
– za002
Nov 25 '18 at 23:42
Unlessstudentis a variable, you are wrong :D Also, note that JavaScript, like most of the popular programming languages, is case-sensitive, andVaris notvar. This is correct:var table = [{"id":0 , "name":"jack","age":25,"profession":"student"},{"id":1 , "name":"nora","age":22,"profession":"student"}]
– Amadan
Nov 25 '18 at 23:53
You can validate a json online here : jsonlint.com
– Shim-Sao
Nov 26 '18 at 0:39
add a comment |
do noteVar table =is invalid syntax, and bothname:jack,andprofession:student}is likely wrong too, strings must be enclosed in delimiters
– CertainPerformance
Nov 25 '18 at 23:37
shouldprofession:studentbeprofession:"student"?
– Dacre Denny
Nov 25 '18 at 23:40
i fixed it thanks , correct me if iam not wrong but"profession":studentis the right syntax
– za002
Nov 25 '18 at 23:42
Unlessstudentis a variable, you are wrong :D Also, note that JavaScript, like most of the popular programming languages, is case-sensitive, andVaris notvar. This is correct:var table = [{"id":0 , "name":"jack","age":25,"profession":"student"},{"id":1 , "name":"nora","age":22,"profession":"student"}]
– Amadan
Nov 25 '18 at 23:53
You can validate a json online here : jsonlint.com
– Shim-Sao
Nov 26 '18 at 0:39
do note
Var table = is invalid syntax, and both name:jack, and profession:student} is likely wrong too, strings must be enclosed in delimiters– CertainPerformance
Nov 25 '18 at 23:37
do note
Var table = is invalid syntax, and both name:jack, and profession:student} is likely wrong too, strings must be enclosed in delimiters– CertainPerformance
Nov 25 '18 at 23:37
should
profession:student be profession:"student" ?– Dacre Denny
Nov 25 '18 at 23:40
should
profession:student be profession:"student" ?– Dacre Denny
Nov 25 '18 at 23:40
i fixed it thanks , correct me if iam not wrong but
"profession":student is the right syntax– za002
Nov 25 '18 at 23:42
i fixed it thanks , correct me if iam not wrong but
"profession":student is the right syntax– za002
Nov 25 '18 at 23:42
Unless
student is a variable, you are wrong :D Also, note that JavaScript, like most of the popular programming languages, is case-sensitive, and Var is not var. This is correct: var table = [{"id":0 , "name":"jack","age":25,"profession":"student"},{"id":1 , "name":"nora","age":22,"profession":"student"}]– Amadan
Nov 25 '18 at 23:53
Unless
student is a variable, you are wrong :D Also, note that JavaScript, like most of the popular programming languages, is case-sensitive, and Var is not var. This is correct: var table = [{"id":0 , "name":"jack","age":25,"profession":"student"},{"id":1 , "name":"nora","age":22,"profession":"student"}]– Amadan
Nov 25 '18 at 23:53
You can validate a json online here : jsonlint.com
– Shim-Sao
Nov 26 '18 at 0:39
You can validate a json online here : jsonlint.com
– Shim-Sao
Nov 26 '18 at 0:39
add a comment |
4 Answers
4
active
oldest
votes
First of all, an object in JavaScript doesn't care if it was constructed out of JSON or not. So your object in JavaScript syntax will look like this:
const x = { name: 'jack', age: 20 };
If you now do Object.keys(x), you will get this:
[ 'name', 'age' ]
And Object.keys(table[0]) should be exactly what you want: the column names of your 'table'
[ 'name', 'age' ]
add a comment |
Object.keys(table[0])
will give you the keys of the first row; presumably the other rows will behave and follow the pattern.
add a comment |
You can get a list of the names of the properties of an object in javascript with this :
Object.keys();
Documentation here :
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
Response of a similar question here :
Getting the object's property name
add a comment |
Just iterate over object keys:
for (var key in table[0]) {console.log(key);}
or (will work in most modern browsers):
Object.keys(table[0]).forEach(key => console.log(key));
Don't forget to check if "table" has elements
Also see other possible options
2
This is not recommended. Try executingObject.prototype.foo = "bar"before running your code for a nice surprise. If you are usingfor ... into iterate over object keys, almost always you'll want to test.hasOwnPropertyto rule out intruders.
– Amadan
Nov 25 '18 at 23:50
True. But I assume in this exact situation nothing is being overridden in Object. Iterating in foreach is just faster and works in old IEs. Here are examples of all techniques: hackernoon.com/…
– Azee
Nov 26 '18 at 0:17
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473088%2fhow-to-get-json-object-titles%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
First of all, an object in JavaScript doesn't care if it was constructed out of JSON or not. So your object in JavaScript syntax will look like this:
const x = { name: 'jack', age: 20 };
If you now do Object.keys(x), you will get this:
[ 'name', 'age' ]
And Object.keys(table[0]) should be exactly what you want: the column names of your 'table'
[ 'name', 'age' ]
add a comment |
First of all, an object in JavaScript doesn't care if it was constructed out of JSON or not. So your object in JavaScript syntax will look like this:
const x = { name: 'jack', age: 20 };
If you now do Object.keys(x), you will get this:
[ 'name', 'age' ]
And Object.keys(table[0]) should be exactly what you want: the column names of your 'table'
[ 'name', 'age' ]
add a comment |
First of all, an object in JavaScript doesn't care if it was constructed out of JSON or not. So your object in JavaScript syntax will look like this:
const x = { name: 'jack', age: 20 };
If you now do Object.keys(x), you will get this:
[ 'name', 'age' ]
And Object.keys(table[0]) should be exactly what you want: the column names of your 'table'
[ 'name', 'age' ]
First of all, an object in JavaScript doesn't care if it was constructed out of JSON or not. So your object in JavaScript syntax will look like this:
const x = { name: 'jack', age: 20 };
If you now do Object.keys(x), you will get this:
[ 'name', 'age' ]
And Object.keys(table[0]) should be exactly what you want: the column names of your 'table'
[ 'name', 'age' ]
answered Nov 25 '18 at 23:55
BojiBoji
787
787
add a comment |
add a comment |
Object.keys(table[0])
will give you the keys of the first row; presumably the other rows will behave and follow the pattern.
add a comment |
Object.keys(table[0])
will give you the keys of the first row; presumably the other rows will behave and follow the pattern.
add a comment |
Object.keys(table[0])
will give you the keys of the first row; presumably the other rows will behave and follow the pattern.
Object.keys(table[0])
will give you the keys of the first row; presumably the other rows will behave and follow the pattern.
answered Nov 25 '18 at 23:44
AmadanAmadan
133k13146197
133k13146197
add a comment |
add a comment |
You can get a list of the names of the properties of an object in javascript with this :
Object.keys();
Documentation here :
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
Response of a similar question here :
Getting the object's property name
add a comment |
You can get a list of the names of the properties of an object in javascript with this :
Object.keys();
Documentation here :
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
Response of a similar question here :
Getting the object's property name
add a comment |
You can get a list of the names of the properties of an object in javascript with this :
Object.keys();
Documentation here :
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
Response of a similar question here :
Getting the object's property name
You can get a list of the names of the properties of an object in javascript with this :
Object.keys();
Documentation here :
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
Response of a similar question here :
Getting the object's property name
answered Nov 25 '18 at 23:45
Shim-SaoShim-Sao
710414
710414
add a comment |
add a comment |
Just iterate over object keys:
for (var key in table[0]) {console.log(key);}
or (will work in most modern browsers):
Object.keys(table[0]).forEach(key => console.log(key));
Don't forget to check if "table" has elements
Also see other possible options
2
This is not recommended. Try executingObject.prototype.foo = "bar"before running your code for a nice surprise. If you are usingfor ... into iterate over object keys, almost always you'll want to test.hasOwnPropertyto rule out intruders.
– Amadan
Nov 25 '18 at 23:50
True. But I assume in this exact situation nothing is being overridden in Object. Iterating in foreach is just faster and works in old IEs. Here are examples of all techniques: hackernoon.com/…
– Azee
Nov 26 '18 at 0:17
add a comment |
Just iterate over object keys:
for (var key in table[0]) {console.log(key);}
or (will work in most modern browsers):
Object.keys(table[0]).forEach(key => console.log(key));
Don't forget to check if "table" has elements
Also see other possible options
2
This is not recommended. Try executingObject.prototype.foo = "bar"before running your code for a nice surprise. If you are usingfor ... into iterate over object keys, almost always you'll want to test.hasOwnPropertyto rule out intruders.
– Amadan
Nov 25 '18 at 23:50
True. But I assume in this exact situation nothing is being overridden in Object. Iterating in foreach is just faster and works in old IEs. Here are examples of all techniques: hackernoon.com/…
– Azee
Nov 26 '18 at 0:17
add a comment |
Just iterate over object keys:
for (var key in table[0]) {console.log(key);}
or (will work in most modern browsers):
Object.keys(table[0]).forEach(key => console.log(key));
Don't forget to check if "table" has elements
Also see other possible options
Just iterate over object keys:
for (var key in table[0]) {console.log(key);}
or (will work in most modern browsers):
Object.keys(table[0]).forEach(key => console.log(key));
Don't forget to check if "table" has elements
Also see other possible options
edited Nov 26 '18 at 0:19
answered Nov 25 '18 at 23:43
AzeeAzee
1,4841319
1,4841319
2
This is not recommended. Try executingObject.prototype.foo = "bar"before running your code for a nice surprise. If you are usingfor ... into iterate over object keys, almost always you'll want to test.hasOwnPropertyto rule out intruders.
– Amadan
Nov 25 '18 at 23:50
True. But I assume in this exact situation nothing is being overridden in Object. Iterating in foreach is just faster and works in old IEs. Here are examples of all techniques: hackernoon.com/…
– Azee
Nov 26 '18 at 0:17
add a comment |
2
This is not recommended. Try executingObject.prototype.foo = "bar"before running your code for a nice surprise. If you are usingfor ... into iterate over object keys, almost always you'll want to test.hasOwnPropertyto rule out intruders.
– Amadan
Nov 25 '18 at 23:50
True. But I assume in this exact situation nothing is being overridden in Object. Iterating in foreach is just faster and works in old IEs. Here are examples of all techniques: hackernoon.com/…
– Azee
Nov 26 '18 at 0:17
2
2
This is not recommended. Try executing
Object.prototype.foo = "bar" before running your code for a nice surprise. If you are using for ... in to iterate over object keys, almost always you'll want to test .hasOwnProperty to rule out intruders.– Amadan
Nov 25 '18 at 23:50
This is not recommended. Try executing
Object.prototype.foo = "bar" before running your code for a nice surprise. If you are using for ... in to iterate over object keys, almost always you'll want to test .hasOwnProperty to rule out intruders.– Amadan
Nov 25 '18 at 23:50
True. But I assume in this exact situation nothing is being overridden in Object. Iterating in foreach is just faster and works in old IEs. Here are examples of all techniques: hackernoon.com/…
– Azee
Nov 26 '18 at 0:17
True. But I assume in this exact situation nothing is being overridden in Object. Iterating in foreach is just faster and works in old IEs. Here are examples of all techniques: hackernoon.com/…
– Azee
Nov 26 '18 at 0:17
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473088%2fhow-to-get-json-object-titles%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
do note
Var table =is invalid syntax, and bothname:jack,andprofession:student}is likely wrong too, strings must be enclosed in delimiters– CertainPerformance
Nov 25 '18 at 23:37
should
profession:studentbeprofession:"student"?– Dacre Denny
Nov 25 '18 at 23:40
i fixed it thanks , correct me if iam not wrong but
"profession":studentis the right syntax– za002
Nov 25 '18 at 23:42
Unless
studentis a variable, you are wrong :D Also, note that JavaScript, like most of the popular programming languages, is case-sensitive, andVaris notvar. This is correct:var table = [{"id":0 , "name":"jack","age":25,"profession":"student"},{"id":1 , "name":"nora","age":22,"profession":"student"}]– Amadan
Nov 25 '18 at 23:53
You can validate a json online here : jsonlint.com
– Shim-Sao
Nov 26 '18 at 0:39