Tôi nhận được JSON phản ứng tiếp theoCách kiểm tra xem phần tử phản hồi JSON có phải là một mảng không?
{
"timetables":[
{"id":87,"content":"B","language":"English","code":"en"},
{"id":87,"content":"a","language":"Castellano","code":"es"}],
"id":6,
"address":"C/Maestro José"
}
Tôi muốn đạt được giả tiếp theo đang chức năng
for(var i in json) {
if(json[i] is Array) {
// Iterate the array and do stuff
} else {
// Do another thing
}
}
Bất kỳ ý tưởng?
Hiện tại, có một hàm gốc trong JavaScript sẽ làm điều này (['Array.isArray (obj)'] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)), mặc dù các trình duyệt cũ hơn vẫn cần dựa vào điều này như là một polyfill. – cimmanon