arr=[] $.each(data,function(key,val){ if(typeof(val)!="undefined"){ arr.push(val.info) //проверяю объект но в него всёравно попадают undefined } }); console.log(arr)//arr[item1,item2,undefined,item4.....] |
2 answers
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
|
valand addgid? where exactly do you get undefined? - Grundy