arr=[] $.each(data,function(key,val){ if(typeof(val)!="undefined"){ arr.push(val.info) //проверяю объект но в него всёравно попадают undefined } }); console.log(arr)//arr[item1,item2,undefined,item4.....] 
  • check val and add gid ? where exactly do you get undefined? - Grundy
  • changing gid, to info, in fact, nothing has changed how the val object was checked. and it is checked how its field develops, and it develops - Grundy

2 answers 2

If you enter into the array val.info , then it should be checked for undefined :

 if (typeof val !== "undefined" && typeof val.info !== "undefined") { arr.push(val.info); } 

    hasOwnPropety checks for the presence of the property itself

    • I write everything as before, `$ .each (data.response, function (key, val) {if (! val.hasOwnProperty (" undefined ")) {arr.push (val.info)}}); ` - test_q_1
    • @ test_q_1, of course, in your example, the presence of the undefined field in the data object is checked, and you put val.info in the array. Determine exactly which field you need to collect and verify it - Grundy