JavaScript - List the properties of an object
Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
-
PloMar
- Posts:48
JavaScript - List the properties of an object
I have an object like this in javascript:
Code: Select all
var obj = {
prop1: 'val 1',
prop2: 'val 2',
prop3: 'val 3'
};
What is the best way to retrieve a list of the property names?
I would like to end up with some variable 'props' such that:
Code: Select all
props == ['prop1', 'prop2', 'prop3']
Admin
Posts:805
You can use the built in
Object.keys method:
Code: Select all
var obj = {
prop1: 'val 1',
prop2: 'val 2',
prop3: 'val 3'
};
var props = Object.keys(obj);
console.log(props); // ['prop1', 'prop2', 'prop3']
Similar Topics
- Hour and Minutes togheter in Javascript
JavaScript - jQuery - Ajax
First post
Dear Coursesweb I can not find out how to add the hours + minutes togheter.
<SCRIPT LANGUAGE= JavaScript >
day = new Date()
hr =...
Last post
See and use the following example:
<script>
var day = new Date();
let hr = day.getHours();
let mn = day.getMinutes();
let se =...
- Display message to every minute in Javascript
JavaScript - jQuery - Ajax
First post
Hello,
On eatch minute from the current hour I wanna have an message
I can not find out how to complete
I hope to get something like this (code...
Last post
If you only want to display a message to every minute, just use the setInterval() function. It calls a function repeatedly, over and over again, at...