Node Js Generate Variable For Javascript Code Example

Snippet 1

   
    var k = 'value'; 
    var i = 0; 
    for(i = 1; i < 5; i++) { 
        eval('var ' + k + i + '= ' + i + ';'); 
    } 
    console.log("value1=" + value1); 
    console.log("value2=" + value2); 
    console.log("value3=" + value3); 
    console.log("value4=" + value4); 
 
 

Snippet 2

  var obj = {
  'prop1' : 'test1',
  'prop2' : 'test2'
}

var keys = Object.keys(obj);

for (let i = 0; i < keys.length; i++) {
  var key = keys[i];
  
  // Here you can use a string value as the property name
  var prop = obj[key];
} 

Similar Snippets


Creating Java Main Method Code Example - java

Find Duplicates In Arraylist Java Code Example - java

Java Creat A Folder Code Example - java

Firestore Find Doc And Set Data Code Example - java

Create Copy Of Array From Another Array Code Example - java

Copyright © Code Fetcher 2020

 

 

Published

Leave a comment

Your email address will not be published. Required fields are marked *