Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
-2
rated 0 times [  2] [ 4]  / answers: 1 / hits: 145401  / 8 Years ago, tue, june 7, 2016, 12:00:00

I am trying to iterate the following json:



{
VERSION : 2006-10-27.a,
JOBNAME : EXEC_,
JOBHOST : Test,
LSFQUEUE : 45,
LSFLIMIT : 2006-10-27,
NEWUSER : 3,
NEWGROUP : 2,
NEWMODUS : 640
}


Here key is dynamic. I want both key = ? and value = ?


More From » arrays

 Answers
34

Use Object.keys() to get keys array and use forEach() to iterate over them.




var data = {
VERSION: 2006-10-27.a,
JOBNAME: EXEC_,
JOBHOST: Test,
LSFQUEUE: 45,
LSFLIMIT: 2006-10-27,
NEWUSER: 3,
NEWGROUP: 2,
NEWMODUS: 640
};

Object.keys(data).forEach(function(key) {
console.log('Key : ' + key + ', Value : ' + data[key])
})




[#61877] Sunday, June 5, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arielle

Total Points: 373
Total Questions: 105
Total Answers: 96

Location: Azerbaijan
Member since Fri, May 12, 2023
1 Year ago
;