JavaScript dictionary with names

前端 未结 8 1182
孤街浪徒
孤街浪徒 2020-12-12 18:08

I want to create a dictionary in JavaScript like the following:

myMappings = [
    { "Name": 10%},
    { "Phone": 10%},
    { "Addres         


        
8条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 18:26

    I suggest not using an array unless you have multiple objects to consider. There isn't anything wrong this statement:

    var myMappings = {
        "Name": 0.1,
        "Phone": 0.1,
        "Address": 0.5,
        "Zip": 0.1,
        "Comments": 0.2
    };
    
    for (var col in myMappings) {
        alert((myMappings[col] * 100) + "%");
    }
    

提交回复
热议问题