create an associative array in jquery

前端 未结 5 1767
迷失自我
迷失自我 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:12

    Check this function

    function shoe_types() {
        var shoeArray = {}; // note this
        $('[type=number]').each(function(){
           $('span[data-field='+$(this).attr('id')+']').text($(this).val());
           shoeArray[$(this).attr('id')] =  parseInt($(this).val()) ;
        });
        return shoeArray;
    
    }
    

    PS: Assuming $(this).attr('id') has all the shoe types

提交回复
热议问题