create an associative array in jquery

前端 未结 5 1768
迷失自我
迷失自我 2021-01-01 23:43

This is what I have so far and the shoe types are boots, wellingtons, leather, trainers (in that order)

I want to iterate through and assign th

5条回答
  •  孤城傲影
    2021-01-02 00:34

    What you want is a function that will return an object {}

    LIVE DEMO

    function shoe_types(){
       var shoeObj = {};
       $('[name="number"]').each(function(){
         shoeObj[this.id] = this.value;
       });
       return shoeObj;
    }
    
    shoe_types(); // [object Object]
    

提交回复
热议问题