猿问

怎么循环ajax返回的数组对象

公共接触前端。萌新不懂就问。感谢各位大佬们。
后台返回的数据:["奥迪","奔驰","五菱宏光"]

$(document).ready(function () {
        $.ajax({
            type:"POST",
            url:"http://localhost:8080/addr/getAllProvince",
            async:false,
            success:function(data){
                //这里要怎么写循环
                for (let i = 0; i <???; i++) {

                }
            }
        })
    });


动漫人物
浏览 873回答 4
4回答

HUWWW

if(data&nbsp;!=&nbsp;null&nbsp;&&&nbsp;data&nbsp;!=&nbsp;''&nbsp;&&&nbsp;data&nbsp;!=&nbsp;undefined){ &nbsp;&nbsp;&nbsp;&nbsp;for(var&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;<&nbsp;data.length;&nbsp;i&nbsp;++){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;name&nbsp;=&nbsp;data[i]; &nbsp;&nbsp;&nbsp;&nbsp;} }

BIG阳

if($.isArray(data)){ &nbsp;&nbsp;&nbsp;&nbsp;data.forEach(function(v){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(v); &nbsp;&nbsp;&nbsp;&nbsp;}); }

ABOUTYOU

var&nbsp;row&nbsp;=&nbsp;["奥迪","奔驰","五菱宏光"]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;row.forEach(function(item,index){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log("["+index+"],"+item) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;})

慕虎7371278

上面答案都可以的,我再补充个var data=["奥迪","奔驰","五菱宏光"];$(data).each(function(i,item){console.log(i'+'item)})0+奥迪1+奔驰2+五菱宏光
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答