javascript - Create Simple Dynamic Array

前端 未结 16 2030
刺人心
刺人心 2020-12-14 06:53

What\'s the most efficient way to create this simple array dynamically.

var arr = [ \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\"];
<         


        
16条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 07:06

    updated = > june 2020

    if are you using node js you can create or append a string value with " ," operator then inside the loop you can

    for (var j = 0; j <= data.legth -1; j++) {
                        lang += data.lang  +", " ;
    
                    }
    
     var langs = lang.split(',')
     console.log("Languages =>",  lang, typeof(lang), typeof(langs), langs) 
     console.log(lang[0]) // here access arrary by index value
                
    
    

    you can see the type of string and object

提交回复
热议问题