JavaScript Dynamic Variable Names

前端 未结 6 811
感动是毒
感动是毒 2020-11-27 21:23

Ok so I want to create variables as a user clicks threw the code every click adds a new variable. I am currently using jquery and javascript I can\'t do it server side this

6条回答
  •  自闭症患者
    2020-11-27 21:34

    Most simple way

    var types = {};
    
    for(var i=1; i<=3; i++){
    types["ashish"+i] = 'The value of dynamic variable, val';
    }
    

    console.log(types);

    you can test it on

    jsfiddle

提交回复
热议问题