How to use 'foreach json object' in JavaScript

Every line of 'foreach json object' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
48function _do(f) {
49 var i, values;
50 for(; a<args_length; ++a) {
51 values = args[a];
52 for(i in values) if(values.hasOwnProperty(i)) f(values[i], i);
53 }
54}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

134function jsonParser(json) {
135 // Number fo indentation
136 n = 2;
137 // Start the loop
138 json.forEach(function(root){
139 root.child.forEach(function(child){
140 // If line doesn't have HB tag
141 if(root.tags.length < 1){
142 child.indent = root.indent+n;
143 }
144 // If line has HB tag and start with HB tag and not comment
145 else if(root.tags.length > 0 && root.tags[0].position == 0 && !root.content.match(/^\/\/\-*.*/)) {
146 child.indent = root.indent;
147 }
148 else if(root.tags.length > 0 && root.tags[0].position != 0 && !root.content.match(/^\/\/\-*.*/)) {
149 child.indent = root.indent+n;
150 }
151 // If child has child, recursive call
152 if(child.child.length > 0)
153 jsonParser([child]);
154 });
155 });
156 return json;
157}

Related snippets