How to declare a dynamic local variable in Javascript

前端 未结 7 2194
我在风中等你
我在风中等你 2021-02-04 08:37

I want to create a local variable dynamically. JavaScript: Dynamically Creating Variables for Loops is not exactly what I am looking for. I dont want an array. I want to access

7条回答
  •  广开言路
    2021-02-04 09:13

    The example below demonstrates how with gets a value from the object.

    var obj = { a : "Hello" }
    with(obj) {
      alert(a) // Hello
    }
    

    But I want to notice: with is deprecated!

提交回复
热议问题